【问题标题】:AWS S3 SDKv2 and image upload ios on turkturk 上的 AWS S3 SDKv2 和图像上传 ios
【发布时间】:2015-01-14 12:54:06
【问题描述】:

我使用以下代码将图像上传到 AWS S3:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:pathComp];
    [UIImageJPEGRepresentation(myImage,0.9) writeToFile:filePath atomically:NO];
    filePath = [NSString stringWithFormat:@"file:///private%@", filePath];
    NSURL* fileUrl = [NSURL URLWithString:filePath];
    AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
    uploadRequest.key = key;
    uploadRequest.body = fileUrl;
    uploadRequest.contentType = @"image/jpeg";

正常上传了,但是在机械土耳其我无法打开预览

This page contains the following errors:

error on line 1 at column 1: Document is empty
error on line 1 at column 1: Encoding error
Below is a rendering of the page up to the first error. 

【问题讨论】:

    标签: ios objective-c amazon-web-services mechanicalturk awss3transfermanager


    【解决方案1】:

    使用NSURL 创建文件URL 时,应使用+ fileURLWithPath:。你应该改变这一行

    NSURL* fileUrl = [NSURL URLWithString:filePath];
    

    NSURL* fileUrl = [NSURL fileURLWithPath:filePath];
    

    您应该仔细检查文件是否已使用AWS Management Console 成功上传。

    此外,默认情况下,所有 Amazon S3 资源(存储桶、对象和相关子资源)都是私有的:只有资源所有者(即创建它的 AWS 账户)可以访问该资源。您可以修改ACL来更改权限。

    【讨论】:

    • 不适合我。图像可以通过右键单击从 MechTurk 下载并另存为。在网站页面打开预览时唯一的错误
    【解决方案2】:

    PaulTaykalo 为 AWS SDK v2 找到了解决方案

    https://github.com/aws/aws-sdk-ios/issues/10
    

    固定方法的链接 http://pastie.org/9340740

    还将此代码添加到 swizzled 方法中

    [headers setValue:contentType forKey:@"Content-Type"];

    【讨论】:

      猜你喜欢
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 2020-04-15
      • 2018-07-13
      • 2015-11-14
      • 2018-03-02
      • 2017-09-04
      相关资源
      最近更新 更多