Some PDFs uploaded to S3 are given the Content-Type 'Image', and then won't open in a browser

0

I am using a Wordpress plugin called Media Cloud, which allows me to upload files into my CMS, which pass through to an S3 bucket. I'm not sure whether this is happening at the plugin level or the S3 level, but sometimes, when the PDF arrives in my bucket, the metadata shows the Content-Type as image/png, and not application/pdf.

This means that the PDF won't open in a browser, because the browser is trying to treat it as an image. Does anyone know why this might happen, and if there is a rule I can set to force all pdfs to have the PDF metadata?

已提問 2 年前檢視次數 1793 次
1 個回答
0

The content-type metadata is set while uploading the file. Have you checked how your CMS processes and identifies files? It sounds like the error happens while the CMS is uploading it into S3. The default behaviour when uploading to S3 depends on the AWS SDK that your CMS uses.

If you can't fix this on the CMS side you could consider creating your own little Lambda function that is triggered when file is uploaded and it then checks if the content-type in metadata matches the file extension. If it doesn't it could update it automatically. Check out how to trigger Lambda based on S3 in our documentation.

profile pictureAWS
專家
Toni_S
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南