亚马逊S3上传文件并获得网址亚马逊、上传文件、网址

2023-09-11 08:31:29 作者:南巷悠长

是否有可能上传一个动作一个TXT / PDF / PNG文件到Amazon S3,并获取上传的文件URL作为响应。如果是这样,则AWS Java SDK的正确的库,我需要在我的Java web应用Struts2的增加。

Is it possible to upload a txt/pdf/png file to Amazon S3 in a single action, and get the uploaded file url as response. If so, is AWS Java sdk the right library that i need to add in my java struts2 webapplication.

请建议我一个解决方案。

Please suggest me a solution for this.

推荐答案

要上传,您可以使用 PutObjectRequest :

To make the file public before uploading you can use the #withCannedAcl method of PutObjectRequest:

myAmazonS3Client.putObject(new PutObjectRequest('some-grails-bucket',  'somePath/someKey.jpg', new    File('/Users/ben/Desktop/photo.jpg')).withCannedAcl(CannedAccessControlList.PublicRead))
 
精彩推荐
图片推荐