简体   繁体   中英

how to upload image to asw s3

I am uploading image from the following code -

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];

I am getting following error -

S3Response.m|-[S3Response connection:didFailWithError:]|234|UserInfo.NSUnderlyingError = Error Domain=kCFErrorDomainCFNetwork Code=-1003 "A server with the specified hostname could not be found." UserInfo=0xac62aa0 {NSErrorFailingURLKey=https://test/images/.s3.amazonaws.com/testimage.jpg

Please suggest me what i am doing wrong.

in bucketName you are storing the path to the folder within your bucket. You need to only have your bucket name there.

It should be: https://bucketname.s3.amazonaws.com/test/images/testimage.jpg

Your's is: https://test/images/.s3.amazonaws.com/testimage.jpg

See the problem? test/images/.s3.amazonaws.com is not a valid domain name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM