Force S3 PDF to be viewed in browser instead of download

前端 未结 4 1105
说谎
说谎 2021-02-09 00:24

So you can force a download by using Content-Disposition: attachment

Content-Disposition: inline is the default and should display in the brows

相关标签:
4条回答
  • 2021-02-09 00:50

    You also need to set the Content-Type correctly. The browser will check the content-type value, and if it isn't something it knows how to display it will always just download the file.

    0 讨论(0)
  • 2021-02-09 01:04

    You have to set your putObject params as follows to view pdf instead of download.

     params = {
            Bucket: process.env.S3_BUCKET,
            Key: <fileName>,
            Body: <fileContent>,
            ContentDisposition:"inline",
            ContentType:"application/pdf"
        };
    
    0 讨论(0)
  • 2021-02-09 01:12

    You need to provide both these meta data inorder to view the file instead of download:

    Content-Disposition: attachment
    Content-Type: application/pdf
    
    0 讨论(0)
  • 2021-02-09 01:12

    Check you file's metadata and remove Content-Disposition entry from that file. and set content type according to the file type.

    Like for text file Content-Type='text/plain'

    image png Content-Type='image/png'

    pdf Content-Type=application/pdf

    pdfxml Content-Type=application/vnd.adobe.pdfxml

    If your file's Content-Type is binary/octet-stream then it will download instead of display.

    Thanks

    0 讨论(0)
提交回复
热议问题