我有一个捕获图像的应用程序,触发获取文档上传策略的请求,并开始上传图像。当用户在前台时,图像会上传,但当用户在后台时,图像不会上传或上传失败。所以我想在应用程序处于后台(后台模式)时上传图像。
在后台(后台模式)上传图片的正确路径是什么?
应用程序是用 Swift 2.3 编写的
任何帮助将不胜感激
谢谢
最佳答案
使用处理后台上传的 AWSS3TransferUtility
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 }
不要忘记在您的应用委托(delegate)中添加以下代码
func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
/*
Store the completion handler.
*/
AWSS3TransferUtility.interceptApplication(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
}
关于ios - 在 iOS Swift 中不使用 AWS SDK 在 Amazon S3 存储桶中上传背景图像(后台模式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42926169/