gpt4 book ai didi

objective-c - Swift/Objective S3 文件上传

转载 作者:可可西里 更新时间:2023-11-01 01:06:40 26 4
gpt4 key购买 nike

我正在尝试使用最近发布的新版本的 AWS,我的旧版本在 android 上运行,但我是 swift 的新手,而我是 AWS S3 的新版本,最近几天被阻止了这个问题。我不断收到操作无法完成的错误消息。 ( cocoa 错误 260。)

这是我的应用委托(delegate)

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
}

最佳答案

尝试使用 fileURLWithPath 类方法实例化 NSURL 对象,这是使用 NSURL 访问本地文件的正确方法。

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/#//apple_ref/occ/clm/NSURL/fileURLWithPath:isDirectory :

关于objective-c - Swift/Objective S3 文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26462723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com