ios - 在 iOS Swift 中不使用 AWS SDK 在 Amazon S3 存储桶中上传背景图像(后台模式)

标签 ios amazon-web-services file-upload amazon-s3 swift2

我有一个捕获图像的应用程序,触发获取文档上传策略的请求,并开始上传图像。当用户在前台时,图像会上传,但当用户在后台时,图像不会上传或上传失败。所以我想在应用程序处于后台(后台模式)时上传图像。

在后台(后台模式)上传图片的正确路径是什么?

应用程序是用 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/

相关文章:

PHP文件上传到mysql

ios - 如何在一个 Uitableview 中添加两个 nib UITableViewCell

ios - 使用 AES256CBC 库解密不会返回相同的值?

amazon-web-services - 自定义资源 Lambda 应在创建时运行,但在第一次更新时运行

amazon-web-services - 如何通过特定用户的 Bearer token 访问与 S3 Bucket 连接的 AWS CloudFront(JWT 自定义身份验证)

java - Apache Commons FileUpload getString() 方法 - Java

iphone - Xcode 4.3.2 + iOS SDK 5.1 异常断点不起作用

ios - 在 iOS 中设置月份和年份的格式

mysql - MySQL 中的 CASE 强制列数据类型为 BIGINT 而不是 INT

java - 使用 Spring MVC 上传文件