Some PDFs uploaded to S3 are given the Content-Type 'Image', and then won't open in a browser
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?
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.
Relevant questions
How do I install the unlimited strength policy for JCE on AWS Workspaces?
asked 2 years agoNetworking Error on S3 management console
asked a year agoUploading greater than 6 MB file to S3 through API Gateway results in Request too long error, Is that expected ?
asked 2 months agoSome PDFs uploaded to S3 are given the Content-Type 'Image', and then won't open in a browser
asked 17 days agoCorrupted Binary Files
asked 18 days agoAccess denied using cyberduck or s3 Browser to upload object into s3 bucket
asked 3 years agoHow to limit s3 mutlipart upload filesize?
asked 21 days agoPrivate S3 bucket and http referer policy for a Wordpress site not working
asked a year agoVideo Embed in WordPress post showing error
asked 4 months agoCreate aws_secret_access_key for S3 bucket
asked 7 months ago