I have an image that I'm uploading to my bucket in AWS this way:
我用AWS的方式上传了一张图片到我的桶里:
BFTask *task = [BFTask taskWithResult:nil];
[[task continueWithBlock:^id(BFTask *task) {
self.URL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"test"]];
NSData *data = UIImagePNGRepresentation(image);
//NSMutableString *dataString = [NSMutableString new];
[data writeToURL:self.URL atomically:YES];
return nil;
}]continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) {
self.uploadRequest1 = [AWSS3TransferManagerUploadRequest new];
self.uploadRequest1.bucket = S3BucketName;
self.uploadRequest1.key = S3KeyUploadName1;
self.uploadRequest1.body = self.URL;
return nil;
}];
AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
[[transferManager upload:self.uploadRequest1] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) {
if (task.error != nil) {
if( task.error.code != AWSS3TransferManagerErrorCancelled
&&
task.error.code != AWSS3TransferManagerErrorPaused
)
{
NSLog(@"Upload Failed!");
}
} else {
self.uploadRequest1 = nil;
NSLog(@"Uploaded!");
}
return nil;
}];
The code for uploading the image works just fine. When I open my bucket I see the image there.
上传图片的代码很好。当我打开水桶时,我看到了那个图像。
Now what I want to do is to get the URL of that image, is there a way to get the URL without getting the image again?
现在我要做的是获取图像的URL,是否有一种方法来获取URL而不需要重新获得图像?
3 个解决方案
#1
6
You don't get it, you create it like:
你没有得到它,你创造它像:
https://s3.amazonaws.com/BUCKET_NAME/FILE_NAME.jpg
https://s3.amazonaws.com/BUCKET_NAME/FILE_NAME.jpg
#2
4
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.body = [NSURL fileURLWithPath:filePath];
uploadRequest.key = fileName;
uploadReuest.bucket = S3BucketName;
[uploadRequest setACL:AWSS3ObjectCannedACLPublicRead];
[uploadRequest setACL AWSS3ObjectCannedACLPublicRead):;
Above Answer is right but you must have to set "ACL" to uploadRequest.
上面的回答是正确的,但是您必须将“ACL”设置为uploadRequest。
In your Question,you are forget to set "ACL".
在您的问题中,您忘记设置“ACL”。
Thanks
谢谢
#3
#1
6
You don't get it, you create it like:
你没有得到它,你创造它像:
https://s3.amazonaws.com/BUCKET_NAME/FILE_NAME.jpg
https://s3.amazonaws.com/BUCKET_NAME/FILE_NAME.jpg
#2
4
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.body = [NSURL fileURLWithPath:filePath];
uploadRequest.key = fileName;
uploadReuest.bucket = S3BucketName;
[uploadRequest setACL:AWSS3ObjectCannedACLPublicRead];
[uploadRequest setACL AWSS3ObjectCannedACLPublicRead):;
Above Answer is right but you must have to set "ACL" to uploadRequest.
上面的回答是正确的,但是您必须将“ACL”设置为uploadRequest。
In your Question,you are forget to set "ACL".
在您的问题中,您忘记设置“ACL”。
Thanks
谢谢