[英]How can we get the view url and download url from amazon s3 bucket?
Uploaded file with two methods.使用两种方法上传文件。 Method 1 .方法一。 file is MultipartFile type文件是 MultipartFile 类型
InputStream input =file.getInputStream();
ObjectMetadata metadata=new ObjectMetadata();
metadata.setContentLength(file.getSize());
amazon.putObject(bucketName, fileName,input,metadata);
Method 2 .方法二。 fileObj is of file type fileObj 是文件类型
amazon.putObject(bucketName, fileName,fileObj);
Output:- String url = amazon.getUrl(bucketName, fileName).toExternalForm();
输出:- String url = amazon.getUrl(bucketName, fileName).toExternalForm();
Method 1: - If I hit the url, it gets downloaded方法 1: - 如果我点击 url,它会被下载
Method 2: - If I hit the url, it can view from the browser.方法 2: - 如果我点击 url,它可以从浏览器中查看。
How do I achieve both view and download from any one method?如何通过任何一种方法实现查看和下载? Also which is more convenient and effective.也更方便有效。 Thanks in advance.提前致谢。
If an object is uploaded to Amazon S3 with Content-Type
metadata, the browser can understand its format and display it (if it knows how).如果一个对象使用Content-Type
元数据上传到 Amazon S3,浏览器可以理解它的格式并显示它(如果它知道如何)。
It would appear that this happens automatically with your Method 2, but boto3 is unable to detect the Content-Type when using Method 1. You would need to add this metadata yourself to produce the same result as Method 2.看起来这会在您的方法 2 中自动发生,但是在使用方法 1 时 boto3 无法检测到 Content-Type。您需要自己添加此元数据以产生与方法 2 相同的结果。
To control what is viewed and downloaded, do it in your HTML:要控制查看和下载的内容,请在 HTML 中执行此操作:
<a href="...">View object</a>
<a href="..." download>Download object</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.