强制在浏览器中查看S3 PDF而不是下载 [英] Force S3 PDF to be viewed in browser instead of download
问题描述
因此您可以使用Content-Disposition: attachment
Content-Disposition: inline
是默认设置,应显示在浏览器中,并且实际上适用于大多数文件,例如PNG,JPG等.
Content-Disposition: inline
is the default and should display in the browser, and it does in fact work with most files like PNG, JPG, etc.
但是由于某种原因,从S3生成预签名URL时,即使我不使用content-disposition:附件标头,PDF文件也始终会强制下载.
But for some reason somehow when generating a presigned URL from S3, PDF files will always force download even if I don't use the content-disposition: attachment header.
我希望能够在浏览器允许的情况下在浏览器中打开PDF
I want to be able to make the PDF open in the browser when the browser allows it
我正在使用来自S3客户端 http:/的预签名URL生成调用/docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURLJavaSDK.html
I am using the presigned URL generate call from S3 client http://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURLJavaSDK.html
推荐答案
检查文件的元数据,然后从该文件中删除 Content-Disposition 条目.并根据文件类型设置内容类型.
Check you file's metadata and remove Content-Disposition entry from that file. and set content type according to the file type.
喜欢 文本文件 Content-Type ='文本/纯文本
Like for text file Content-Type='text/plain'
image png 内容类型 ='image/png'
image png Content-Type='image/png'
pdf 内容类型 =应用程序/pdf
pdf Content-Type=application/pdf
pdfxml 内容类型 = application/vnd.adobe.pdfxml
pdfxml Content-Type=application/vnd.adobe.pdfxml
如果文件的Content-Type是二进制/八位字节流,那么它将下载而不是显示.
If your file's Content-Type is binary/octet-stream then it will download instead of display.
谢谢
这篇关于强制在浏览器中查看S3 PDF而不是下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!