我有一张图片,我正在以这种方式上传到我的存储桶:
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;
}];
上传图片的代码工作得很好。当我打开我的水桶时,我看到那里的图像。
现在我要做的是获取该图片的网址,有没有办法获取网址而不再获取图片?
答案 0 :(得分:6)
你没有得到它,你创建它:
答案 1 :(得分:4)
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.body = [NSURL fileURLWithPath:filePath];
uploadRequest.key = fileName;
uploadReuest.bucket = S3BucketName;
[uploadRequest setACL:AWSS3ObjectCannedACLPublicRead];
以上答案是正确的,但您必须将“ACL”设置为uploadRequest。
在您的问题中,您忘记设置“ACL”。
谢谢
答案 2 :(得分:2)