Skip to content

Instantly share code, notes, and snippets.

@GodsEye-07
Last active February 4, 2020 12:46
Show Gist options
  • Save GodsEye-07/3852c173a989cc52541871a5ff8cea8c to your computer and use it in GitHub Desktop.
Save GodsEye-07/3852c173a989cc52541871a5ff8cea8c to your computer and use it in GitHub Desktop.
AWSS3TransferManager
let bucketName = "***** your bucket name *****"
func uploadFile(with resource: String, type: String) { //1
let key = "\(resource).\(type)"
let localImagePath = Bundle.main.path(forResource: resource, ofType: type)! //2
let localImageUrl = URL(fileURLWithPath: localImagePath)
let request = AWSS3TransferManagerUploadRequest()!
request.bucket = bucketName //3
request.key = key //4
request.body = localImageUrl
request.acl = .publicReadWrite //5
//6
let transferManager = AWSS3TransferManager.default()
transferManager.upload(request).continueWith(executor: AWSExecutor.mainThread()) { (task) -> Any? in
if let error = task.error {
print(error)
}
if task.result != nil { //7
print("Uploaded \(key)")
//do any task
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment