我没有触及AWS库,但每当我尝试将图像上传到S3时,我都会收到此错误。
我有Xcode 7和AWS SDK 2.2.6的最新版本。
我使用此代码上传图片:
// Upload image
let path: String = NSTemporaryDirectory()
let path_url: NSURL = (NSURL(string: path)?.URLByAppendingPathComponent("prof.png"))!
let imageData: NSData = UIImageJPEGRepresentation(image, 0.4)!
imageData.writeToFile(path_url.URLString, atomically: true)
let url: NSURL = NSURL(fileURLWithPath: path as String)
let upload_request = AWSS3TransferManagerUploadRequest()
upload_request.bucket = s3_bucket_name
upload_request.ACL = AWSS3ObjectCannedACL.AuthenticatedRead
upload_request.key = "/prof.png"
upload_request.body = url;
upload_request.uploadProgress = { (bytesSent, totalBytesSent, totalBytesExpectedToSend) -> Void in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if totalBytesExpectedToSend > 0 {
print("\(totalBytesSent)/\(totalBytesExpectedToSend)total bytes sent")
}
})
}
//
之前有用,但我不确定当我通过cocoapods或xcode 7更新AWS库时是否会发生这种情况。
我删除了/ Pods,Podfile.lock和DerivedData文件夹,我也清理了项目并重新安装了AWS 2.2.6(pod install
)
答案 0 :(得分:0)
我用另一种方法来保存临时文件。
// temporary
let fileName = NSProcessInfo.processInfo().globallyUniqueString.stringByAppendingString(".png")
let fileURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent(fileName)
let imageData = UIImageJPEGRepresentation(image, 0.4)!
do {
try imageData.writeToURL(fileURL, options: .DataWritingAtomic)
} catch _ {
print("didn't write into it.")
}
// ...
并更新正文网址。
upload_request.body = fileURL;