[英]How to upload a file to Amazon S3 and get the url in response using iOS
我使用了Amazon Sample Code中的代碼片段。 以下代碼將數據上傳到amazon S3存儲桶,但我需要上傳文件的URL。 我正朝着正確的方向前進嗎? 或者有人能指出我正在犯的錯誤
任何形式的幫助將不勝感激。
AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.bucket = S3BucketName;
uploadRequest.key = S3UploadKeyName;
uploadRequest.body = self.uploadFileURL;
//uploadRequest.contentLength = [NSNumber numberWithUnsignedLongLong:fileSize];
[[transferManager upload:uploadRequest] continueWithBlock:^id(BFTask *task) {
// Do something with the response
AWSS3TransferManagerUploadOutput *uploadOutPut = task.result;
NSLog(@"bftask:%@",uploadOutPut); // Upload out put gives me the following response
return nil;
}];
bfTask響應:
bftask:<AWSS3TransferManagerUploadOutput: 0x1706606c0> {
ETag = "\"0aefedfa36b687a74025b1ad50f3101f\"";
serverSideEncryption = 0;
}
如果您只需要下載該文件,則可以使用AWSS3TransferManagerDownloadRequest
使用SDK下載文件。 或者,您可以使用AWSS3PreSignedURLBuilder
生成預先簽名的URL以下載文件。
如果您只想知道對象的URL,則URL遵循以下模式:
https://<YourS3Endpoint>/<YourBucketName>/<YourObjectKeyName>
Amazon S3中的任何對象默認都是私有的,不可公開讀取。 如果要使其可公開讀取,則需要在AWSS3TransferManagerUploadRequest
對象上設置ACL
。
有關更多詳細信息,請參閱Amazon S3 Bucket公共訪問注意事項 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.