[英]AWS S3 SDKv2 and image upload ios on turk
I uploaded image to AWS S3 with with code : 我使用以下代码将图像上传到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";
It's uploaded normally, but in mechanical turk i can't open preview 它已正常上传,但是在机械特克中我无法打开预览
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.
When creating a file URL using NSURL
, you should use + fileURLWithPath:
. 使用
NSURL
创建文件URL时,应使用+ fileURLWithPath:
You should change this line 您应该更改此行
NSURL* fileUrl = [NSURL URLWithString:filePath];
to 至
NSURL* fileUrl = [NSURL fileURLWithPath:filePath];
You should double check if the file was successfully uploaded using the AWS Management Console . 您应该仔细检查文件是否已使用AWS管理控制台成功上传。
Also, by default, all Amazon S3 resources - buckets, objects, and related subresources - are private: only the resource owner, an AWS account that created it, can access the resource. 另外,默认情况下,所有Amazon S3资源-存储桶,对象和相关子资源-都是私有的:只有资源所有者(创建该资源的AWS账户)才能访问该资源。 You can modify
ACL
to change the permission. 您可以修改
ACL
来更改权限。
Finded solution for AWS SDK v2 by PaulTaykalo 找到PaulTaykalo的适用于AWS开发工具包v2的解决方案
https://github.com/aws/aws-sdk-ios/issues/10
Link for fixed method http://pastie.org/9340740 固定方法的链接http://pastie.org/9340740
Also added this code to swizzled method
还将这段代码添加到混乱的方法中
[headers setValue:contentType forKey:@"Content-Type"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.