0
我試圖在S3桶上發送照片。好吧,這是很快就沒有記錄的地獄,而且sdks在這裏和那裏都是碎片化的,它在我身邊很糟糕,目前沒有任何工作:亞馬遜S3斯威夫特 - 簡單的上傳需要年齡,最後不會出現在桶裏
我的上傳過程持續進行,但速度非常慢(讓我們說一個5 meg圖像需要10分鐘),大多數時候,上傳會凍結並重新開始。
但奇怪的是,它終於成功時,文件不會顯示在我的桶中。我曾試着將文件上傳到不存在的水桶和過程仍然繼續(???)
這裏是我的憑據LOC(桶是華東加州)
let credentialsProvider = AWSCognitoCredentialsProvider(
regionType: AWSRegionType.USEast1, identityPoolId: "us-east-1:47e88493-xxxx-xxxx-xxxx-xxxxxxxxx")
let defaultServiceConfiguration = AWSServiceConfiguration(
region: AWSRegionType.USEast1, credentialsProvider: credentialsProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = defaultServiceConfiguration
現在這裏是我的上傳功能
func uploadImage(){
//defining bucket and upload file name
let S3BucketName: String = "witnesstestbucket"
let S3UploadKeyName: String = "public/testImage.jpg"
let expression = AWSS3TransferUtilityUploadExpression()
expression.uploadProgress = {(task: AWSS3TransferUtilityTask, bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) in
dispatch_async(dispatch_get_main_queue(), {
let progress = Float(totalBytesSent)/Float(totalBytesExpectedToSend)
print("Progress is: \(progress)")
print (Float(totalBytesExpectedToSend))
})
}
self.uploadCompletionHandler = { (task, error) -> Void in
dispatch_async(dispatch_get_main_queue(), {
if ((error) != nil){
print("Failed with error")
print("Error: \(error!)");
}
else{
print("Sucess")
}
})
}
let transferUtility = AWSS3TransferUtility.defaultS3TransferUtility()
transferUtility.uploadData(imagedata, bucket: S3BucketName, key: S3UploadKeyName, contentType: "image/jpeg", expression: expression, completionHander: uploadCompletionHandler).continueWithBlock { (task) -> AnyObject! in
if let error = task.error {
print("Error: \(error.localizedDescription)")
}
if let exception = task.exception {
print("Exception: \(exception.description)")
}
if let _ = task.result {
print("Upload Starting!")
}
return nil;
}
}
@IBAction func post(sender: UIButton) {
// AW S3 upload
uploadImage()
}
要清楚,我的圖象 - NSData的來自一個UIImage,從collectionviewcell牽強:
self.imagedata = UIImageJPEGRepresentation(img!, 05.0)!
有什麼我可以更新,以瞭解我的錯在哪裏? 在此先感謝:)