Amazon S3 files uploaded using AWS SDK for PHP is always “application/octet-stream”?

Question:

According to the docs, contentType is optional and it will attempt to determine the correct mime-type based on the file extension. However, it never seemed to guess the mime-type and always defaults to application/octet-stream

Here’s my code:

Here’s a screenshot of my AWS console:

enter image description here

How do you actually automatically set the proper Content Type without setting contentType option, or do you really have to set it manually?

Additional info: If I download a file from the console (that I originally uploaded through SDK) then upload it again using the console, the proper Content-Type is set (ex: image/gif for GIF files instead of application/octet-stream)

Answer:

Try to add ‘contentType’ key to your options array when creating object and use ‘body’ instead of ‘fileUpload’. For example:

Successfully creates file with text/xml content type. As I know Content-Type isn’t set automatically when uploading through SDK. But where’s the problem to derminate mime type from PHP side and set the ‘contentType’ property?

Leave a Reply