出於某種原因,上傳到S3確實無法正常工作,而我卻能夠使下載功能正常工作。XCode Swift AWS S3上傳不起作用
這是我的上載的代碼:
@IBAction FUNC uploadFile(_發件人:的UIButton){
let CognitoRegionType = AWSRegionType.USWest2 // e.g. AWSRegionType.USEast1
let CognitoIdentityPoolId = "us-west-2:3c00122a-866c-4ce4-9dd3-ee23c16e58f3"
let DefaultServiceRegionType = AWSRegionType.USWest1 // e.g. AWSRegionType.USEast1
let S3BucketName = "snappcastphotos"
let credentialsProvider = AWSCognitoCredentialsProvider(regionType:CognitoRegionType, identityPoolId: CognitoIdentityPoolId)
let configuration = AWSServiceConfiguration(region: DefaultServiceRegionType , credentialsProvider:credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
let uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest?.bucket = S3BucketName
uploadRequest?.key = "bingo"
uploadRequest?.body = URL(fileURLWithPath: "https://stackoverflow.com/users/rhom/desktop/test.rtf")
let transferManager = AWSS3TransferManager.default()
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
})
}
和這個碼產生以下錯誤/輸出:
錯誤上傳:可選(「bingo」)錯誤:錯誤域= com.amazonaws.AWSS3ErrorDomain代碼= 0「(null)」UserInfo = {HostId = KAsbvIqiY67dr/64f3uvZPB1Lr5Vj7eNNV198DLai/RG/tA + v3To8CBbnbFSM00V2COZnzebx/M =,Message =請求正文意外終止,Code = IncompleteBody,RequestId = A95236E53A1B8FE8}
任何人有什麼想法?我找不到任何線索,爲什麼使用Cognito和S3的下載工作,但上傳不起作用....
是的我在Cognito和S3存儲桶檢查權限,以確保他們有讀/寫...將繼續搜索,但thx評論 – user3424472