swift2 在iOS Swift中不使用AWS SDK的情况下,在Amazon S3桶中上传背景图像(背景模式)

y53ybaqx  于 2022-11-06  发布在  Swift
关注(0)|答案(1)|浏览(302)

我有一个捕获图像的应用程序,触发获取文档上传策略的请求,并开始上传图像。当用户在前台时,图像会上传,但当用户在后台时,图像不会上传或上传失败。因此,我想在应用程序在后台时上传图像(后台模式)。
图像后台(后台模式)上传的正确路径是什么?
该应用程序采用Swift 2.3编写
任何帮助都将不胜感激
谢谢

vx6bjr1n

vx6bjr1n1#

使用处理后台上载的AWSS3TransferUtility

  1. import AWSS3
  2. let transferUtility = AWSS3TransferUtility.default()
  3. //In order to customize the header information, we use the AWSS3TransferUtilityUploadExpression class
  4. let expression = AWSS3TransferUtilityUploadExpression()
  5. //We want our file to be publicly available by default
  6. expression.setValue("public-read", forRequestParameter: "x-amz-acl")
  7. //Copy the custom Meta information into the expression
  8. transferUtility.uploadFile(uploadRequest.body, bucket: uploadRequest.bucket ?? "", key: uploadRequest.key ?? "", contentType: uploadRequest.contentType ?? "", expression: expression) { (task, error) in }

不要忘记在应用程序委托中添加以下代码

  1. func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
  2. /*
  3. Store the completion handler.
  4. */
  5. AWSS3TransferUtility.interceptApplication(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
  6. }
展开查看全部

相关问题