我正面臨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