Last active
February 4, 2020 12:46
-
-
Save GodsEye-07/3852c173a989cc52541871a5ff8cea8c to your computer and use it in GitHub Desktop.
AWSS3TransferManager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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