我正面临S3的问题。 经过3小时的故障排除(在此期间,我了解了IAM角色&设法创建它们)我卡住试图上传fb档案图片到亚马逊S3。将jpg上传到S3:“请求主体意外终止”
我的代码:
if let imageData = NSData(contentsOf: NSURL(string: url) as! URL) {
let fileName = ProcessInfo.processInfo.globallyUniqueString + ".jpg"
let fileURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(fileName)
let image = UIImage(data: imageData as Data)
let imageData = UIImageJPEGRepresentation(image!, 1.0)!
do {
try imageData.write(to: fileURL! as URL)
} catch _ {
self.log.error("Could not write to file.")
}
let transferManager = AWSS3TransferManager.default()
let uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest?.bucket = "app-files"
uploadRequest?.key = "user-data/" + awsId! + "_primary_profile_picture.jpg"
uploadRequest?.body = fileURL!
transferManager.upload(uploadRequest!).continueWith(executor: AWSExecutor.mainThread(), block: { (task:AWSTask<AnyObject>) -> Any? in
if let error = task.error as? NSError {
if error.domain == AWSS3TransferManagerErrorDomain, let code = AWSS3TransferManagerErrorType(rawValue: error.code) {
switch code {
case .cancelled, .paused:
break
default:
print("Error uploading: \(uploadRequest?.key) Error: \(error)")
}
} else {
print("Error uploading: \(uploadRequest?.key) Error: \(error)")
}
return nil
}
let uploadOutput = task.result
print("Upload complete for: \(uploadRequest?.key)")
return nil
})
}
** **问题 我不断收到来自S3一The request body terminated unexpectedly
错误,看起来像这样:
Error uploading: Optional("user-data/eu-west-1:xxxx-xxxx-xxxx-xxxx-xxxxxxxxxx_primary_profile_picture.jpg")
Error: Error Domain=com.amazonaws.AWSS3ErrorDomain Code=0 "(null)"
UserInfo={HostId=XXX,
Message=The request body terminated unexpectedly,
Code=IncompleteBody,
RequestId=1485A0FFBD7819D7}
我不知道是怎么回事错误,我已调试,并fileName,fileURL,imageData似乎很好
SDK v2.5.1中存在一个bug,如果可以的话,尝试降级到2.5.0。 – donkon
我不得不升级,因为迅速3支持:/ with 2.5没有任何工作(认知,发电机,...) –
斯威夫特3支持在2.5.0中引入该变化不应该打破任何列出的服务...理论上。你能否提供一些关于认知和发电机不起作用的细节? – donkon