Reputation: 381
I have an application that capture image/images, the request is fired for getting the document upload policies, and uploading the image/images starts. When user is in the foreground the image/images uploads but when user is in the background the image/images do not gets uploaded or failed to upload. So I want to upload the image/images when the application is in the background (Background Mode).
What is the right path to follow for the Background (Background Mode) Uploading of the image/images?
The application is written in Swift 2.3
Any Help would be Appriciated
Thanks
Upvotes: 2
Views: 1968
Reputation: 1340
Use AWSS3TransferUtility which handles background uploads
import AWSS3
let transferUtility = AWSS3TransferUtility.default()
//In order to customize the header information, we use the AWSS3TransferUtilityUploadExpression class
let expression = AWSS3TransferUtilityUploadExpression()
//We want our file to be publicly available by default
expression.setValue("public-read", forRequestParameter: "x-amz-acl")
//Copy the custom Meta information into the expression
transferUtility.uploadFile(uploadRequest.body, bucket: uploadRequest.bucket ?? "", key: uploadRequest.key ?? "", contentType: uploadRequest.contentType ?? "", expression: expression) { (task, error) in }
Dont forget to add below code in your app delegate
func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
/*
Store the completion handler.
*/
AWSS3TransferUtility.interceptApplication(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
}
Upvotes: 3