首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AWSS3TransferManager NSCocoaErrorDomain Code=2误差

AWSS3TransferManager NSCocoaErrorDomain Code=2误差
EN

Stack Overflow用户
提问于 2015-01-20 08:58:10
回答 1查看 348关注 0票数 1

我的代码有以下奇怪的错误。NSFilemanager中的文件路径有限制吗?真正奇怪的是,当通过AWS S3上传时,这个路径工作得很好。

URLSession:dataTask:didReceiveResponse:completionHandler:] 错误:无法创建文件路径:/profilePicture12.jpeg

代码语言:javascript
复制
    AWSStaticCredentialsProvider *credentialsProvider = [AWSStaticCredentialsProvider credentialsWithAccessKey:AWS_Access_Key secretKey:AWS_Secret_Key];
AWSServiceConfiguration *configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSWest1 credentialsProvider:credentialsProvider];
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
self.downloadRequest = [AWSS3TransferManagerDownloadRequest new];

//bucket and image name
self.downloadRequest.bucket = AWS_Bucket_Name;
self.downloadRequest.key = S3_Link;


//unique customer path to store download
NSString* uniqueCustomerPath = [NSString stringWithFormat:@"profilePicture%ld.jpeg", (long)self.current_customer.id];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString  *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:uniqueCustomerPath];
self.downloadRequest.downloadingFileURL = [NSURL fileURLWithPath:uniqueCustomerPath];

AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
[[transferManager download:self.downloadRequest] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task){
    if (task.error != nil) {
        NSLog(@"Error: [%@]", task.error);}

    else {
      ///do stuff
    }
    return nil;
}];
EN

回答 1

Stack Overflow用户

发布于 2015-04-01 20:13:32

下面的代码片段适用于我。我怀疑你在试图将文件写入不可写的路径。另一个猜测是S3_Link设置为键。如果它是完整的S3路径,则可能无法工作。在那里试试文件名。

代码语言:javascript
复制
NSURL *bucketFileURL = [NSURL URLWithString:url];
NSString *key = [bucketFileURL lastPathComponent];
NSString *downloadingFilePath = [DOCUMENTS_DIRECTORY stringByAppendingPathComponent:key];

NSURL *downloadingFileURL = [NSURL fileURLWithPath:downloadingFilePath];

AWSS3TransferManagerDownloadRequest *downloadRequest = [AWSS3TransferManagerDownloadRequest new];
downloadRequest.bucket = @"my-bucket-name";
downloadRequest.key = key;
downloadRequest.downloadingFileURL = downloadingFileURL;

AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
[[transferManager download:downloadRequest] continueWithBlock:^id(BFTask *task) {

     if (task.result) {
         UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:downloadRequest.downloadingFileURL]];
         callback(img);
     } else if (task.error) {
         NSLog(@"Download Error: %@", task.error);
     }

     return nil;
 }];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28041178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档