I am new to AWS and using it for iOS app.
I'm trying to upload images from my iOS app to bucket named, "img.haraj.com.sa". When I upload any image, they aren't shown in bucket. But when I change the target to bucket named "haraj", they are uploaded and shown in the bucket.
Here's the policy:
{
"Statement": [
{
"Sid": "**********hidden**********",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::haraj/*"
]
}
]
}
I modify this for changing the target bucket. I also created other buckets with name "img1.haraj.com.sa" and tried uploading images and unfortunately they also failed.
It seems there is some problem with having bucket names with dots (.) and without dots. Names of buckets without dots works with iOS app and the names with dots doesn't work. I'm not sure though. But I'm facing this problem. I don't receive any error response in app code.
Here's part of my iOS app implementation:
- (void)postAdButtonPushed:(id)sender
{
DLog(@"Post Ad")
AmazonS3Client *s3Client = [[AmazonS3Client alloc] initWithAccessKey:AWS_ACCESS_KEY_ID withSecretKey:AWS_SECRET_KEY];
s3Client.timeout = 240;
NSString *bucketName = [NSString stringWithFormat:@"img.haraj.com.sa"];
NSString *imageName = [NSString stringWithFormat:@"testimage.jpg"];
S3PutObjectRequest *objReq = [[S3PutObjectRequest alloc] initWithKey:imageName inBucket:bucketName];
objReq.contentType = @"image/jpeg";
UIImage *testImageToUpload = [self.imagesToUpload objectAtIndex:0];
NSData *imageData = UIImageJPEGRepresentation(testImageToUpload, 0.8);
objReq.data = imageData;
objReq.delegate = self;
objReq.contentLength = [imageData length];
[s3Client putObject:objReq];
}
- (void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response
{
DLog(@"response: %@", response.description)
}
- (void)request:(AmazonServiceRequest *)request didFailWithError:(NSError *)error
{
DLog(@"Req failed: %@", error.description)
}
I also created a thread on Amazon Forum at: AWS Upload image to Bucket iOS app
Any help would be appreciated. Thank you!