Force S3 PDF to be viewed in browser instead of download

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"
    };

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.


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