如何将图像上传到aws s3

时间:2013-08-21 12:44:55

标签: ios objective-c amazon-s3

我从以下代码上传图片 -

NSData *imageData = UIImageJPEGRepresentation(image, 1.0);

 AmazonS3Client *s3Client = [[[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY] autorelease];

   s3Client.timeout = 240;
   NSString *bucketName = [NSString stringWithFormat:@"test/images/"];
   NSString *imageName = [NSString stringWithFormat:@"testimage.jpg"];

   S3PutObjectRequest *objReq = [[S3PutObjectRequest alloc] initWithKey:imageName inBucket:bucketName];
   objReq.contentType = @"image/jpeg";
   objReq.data = imageData;
   objReq.delegate = self;
   objReq.contentLength = [imageData length];
   [s3Client putObject:objReq];

我收到以下错误 -

S3Response.m | - [S3Response connection:didFailWithError:] | 234 | UserInfo.NSUnderlyingError = Error Domain = kCFErrorDomainCFNetwork Code = -1003“找不到具有指定主机名的服务器。” UserInfo = 0xac62aa0 {NSErrorFailingURLKey=https://test/images/.s3.amazonaws.com/testimage.jpg

请告诉我我做错了什么。

1 个答案:

答案 0 :(得分:0)

bucketName中,您正在存储存储桶中文件夹的路径。你只需要在那里有你的桶名。

它应该是: https://bucketname.s3.amazonaws.com/test/images/testimage.jpg

你的是: https://test/images/.s3.amazonaws.com/testimage.jpg

看到问题? test / images / .s3.amazonaws.com不是有效的域名。