【发布时间】:2014-12-15 06:18:15
【问题描述】:
我正在尝试使用最近发布的新版本 AWS,我有旧版本在 android 上运行,但我是 swift 和新版本 AWS S3 的新手,并且在过去几天被阻止这个问题。我不断收到无法完成操作的错误消息。 (可可错误 260。)
这是我的应用委托
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let credentialsProvider = AWSCognitoCredentialsProvider.credentialsWithRegionType(
AWSRegionType.USEast1,
accountId: cognitoAccountId,
identityPoolId: cognitoIdentityPoolId,
unauthRoleArn: cognitoUnauthRoleArn,
authRoleArn: cognitoAuthRoleArn)
let defaultServiceConfiguration = AWSServiceConfiguration(
region: AWSRegionType.USEast1,
credentialsProvider: credentialsProvider)
AWSServiceManager.defaultServiceManager().setDefaultServiceConfiguration(defaultServiceConfiguration)
AWSServiceManager.defaultServiceManager().setDefaultServiceConfiguration(defaultServiceConfiguration)
return true
}
我尝试将图像上传到存储桶的位置的代码
let fileUrl = NSURL(string:imagePath!)
println(imagePath)
UIImageJPEGRepresentation(self.image, 1).writeToURL(fileUrl, atomically: true)
var indent:NSString = "closr"
var uploadRequest:AWSS3TransferManagerUploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest.bucket = "closr-bucket"
uploadRequest.key = "filename.jpg"
uploadRequest.contentType = "image/jpeg"
uploadRequest.body = fileUrl
uploadRequest.uploadProgress = { (bytesSent:Int64, totalBytesSent:Int64, totalBytesExpectedToSend:Int64) -> Void in
dispatch_sync(dispatch_get_main_queue(), {() -> Void in
println(totalBytesSent)
})
}
AWSS3TransferManager.defaultS3TransferManager().upload(uploadRequest).continueWithBlock { (task) -> AnyObject! in
if (task.error != nil) {
//failed
println("failed")
println(task.error.code)
println(task.error.localizedDescription)
} else {
//completed
println("completed")
}
return nil
}
【问题讨论】:
标签: objective-c amazon-web-services swift amazon-s3 amazon-cognito