迅速将文本/日志文件上传到亚马逊S3

时间:2018-08-24 06:40:18

标签: swift amazon-s3 swift3 awss3transfermanager

当我尝试将文本文件从本地设备上载到aws s3存储桶时,导致Message的正文错误:您未提供Content-Length HTTP标头指定的字节数。请查看下面的代码段。

let uploadRequest = AWSS3TransferManagerUploadRequest()!

uploadRequest.body = localTextURL

uploadRequest.key = filename

uploadRequest.bucket = S3BucketName

uploadRequest.contentLength = 2849623

let transferManager = AWSS3TransferManager.default()

transferManager.upload(uploadRequest).continueWith(executor: 

AWSExecutor.mainThread(),block: { (task) -> AnyObject! in           

if let error = task.error {
                print("Upload failed (\(error))")
            }

            if task.result != nil {

                print("uploaded to \(task.result)")

            }
            else {
                print("Unexpected empty result.")
            }
            return nil
        })

0 个答案:

没有答案