亚马逊S3上传文件并获得网址 [英] Amazon S3 upload file and get URL

查看:418
本文介绍了亚马逊S3上传文件并获得网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能上传一个动作一个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.

推荐答案

要上传,您可以使用 #withCannedAcl 方法之前使文件公开> 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))

这篇关于亚马逊S3上传文件并获得网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆