Search code examples
htmlpdfamazon-s3embedpre-signed-url

Adding s3 signed url in embed for a pdf doesn't work


The url which looks like https://abc.s3.ap-south-1.amazonaws.com/1/2/4/2018/26/pdf.pdf_1537903203247/V0/output/pdf.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=Q434A%2F200926%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20180926T053715Z&X-Amz-Expires=900&X-Amz-Signature=f3996e2401e95e7ebd071187fd55ead39c5296b1cf4d968&X-Amz-SignedHeaders=host

Isn't getting displayed , however the url gets downloaded separately.I have modified the url here.But the actual url works and downloads the pdf if opened in a different tab. Is there a workaround?


Solution

  • As @Michael-sqlbot correctly pointed out. The content-type had to be application/pdf. Javascript code for reference :

    var s3 = new AWS.S3({
                apiVersion: '2006-03-01',
                region: 'ap-abc-1',
                params: {
                    Bucket: BucketName,
                    ServerSideEncryption: "AES256",
                    ContentType: 'application/pdf'
                }
            });
    

    It makes sense that the browser to understand that the url is actually a pdf, it's necessary to add this content-type to it.However, I want to point out that for other file-types like mp3,mp4,jpg,png etc. this was not required in my particular case.Don't know if it is universally true.