bel*_*kar 9 permissions file-upload image amazon-s3 ios
由于我们似乎只限于桶的数量,我正在试图弄清楚如何完成以下操作:
我在文档中遗漏了什么吗?我感谢您对此问题的任何反馈.
Tim*_*ber 21
为了解决这个问题,我开始在自己的iOS SDK亚马逊的示例代码,找到这里.在SDK zip中,可以在以下位置找到感兴趣的示例项目samples/S3_Uploader.
要从该示例项目获取上传图像公开的项目,您只需在正确的位置添加一行:
por.cannedACL = [S3CannedACL publicRead];
Run Code Online (Sandbox Code Playgroud)
其中por在S3PutObjectRequest用于上载图像.
我的项目上传代码如下所示(看起来几乎与亚马逊的示例代码相同):
NSString *uuid = @""; // Generate a UUID however you like, or use something else to name your image.
UIImage *image; // This is the UIImage you'd like to upload.
// This URL is not used in the example, but it points to the file
// to be uploaded.
NSString *url = [NSString pathWithComponents:@[ @"https://s3.amazonaws.com/", AWS_PICTURE_BUCKET, uuid ]];
// Convert the image to JPEG data. Use UIImagePNGRepresentation for pngs
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
// Create the S3 Client.
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:AWS_ACCESS_KEY_ID withSecretKey:AWS_SECRET_KEY];
@try {
// Create the picture bucket.
[s3 createBucket:[[S3CreateBucketRequest alloc] initWithName:AWS_PICTURE_BUCKET]];
// Upload image data. Remember to set the content type.
S3PutObjectRequest *por = [[S3PutObjectRequest alloc] initWithKey:uuid inBucket:AWS_PICTURE_BUCKET];
por.contentType = @"image/jpeg"; // use "image/png" here if you are uploading a png
por.cannedACL = [S3CannedACL publicRead];
por.data = imageData;
por.delegate = self; // Don't need this line if you don't care about hearing a response.
// Put the image data into the specified s3 bucket and object.
[s3 putObject:por];
}
@catch (AmazonClientException *exception) {
NSLog(@"exception");
}
Run Code Online (Sandbox Code Playgroud)
AWS_ACCESS_KEY_ID和AWS_SECRET_KEY是的,当然,你的AWS证书,并AWS_PICTURE_BUCKET为您的照片桶.