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

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

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

vx6bjr1n

vx6bjr1n1#

使用处理后台上载的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 }

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

func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
    /*
     Store the completion handler.
     */
    AWSS3TransferUtility.interceptApplication(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
}

相关问题