Content-Type when uploading to S3

7,666 views
Skip to first unread message

Alex B

unread,
Jul 22, 2014, 3:17:09 PM7/22/14
to jquery-f...@googlegroups.com
Images uploaded to S3 have their `Content-Type` set to `binary/octet-stream` as opposed to an image type such as `image/jpeg` or `image/png` or `image/gif`.

Could you kindly advise me as to how to automatically set the content-type?

If left set to `binary/octet-stream`, images are "downloaded" rather than displayed (or when a display is forced, a Javascript console message appears: "*Resource interpreted as Image but transferred with MIME type binary/octet-stream*").

I was able to replicate this using jQuery-File-Upload-9.6.0/basic-plus.html adjusted just enough to upload to S3.



Alex B

unread,
Jul 22, 2014, 5:47:02 PM7/22/14
to jquery-f...@googlegroups.com
I am using Carrierwave to post-process my images, and by adding the following two lines to the uploader the Content-Type is set properly (on the post-processed images).

        include CarrierWave::MimeTypes
        process :set_content_type


Alex B

unread,
Jul 22, 2014, 5:49:02 PM7/22/14
to jquery-f...@googlegroups.com
That said, it would still be nice to know if it is possible to set the content-type of the uploaded images, via jQuery File Upload Plugin.

Mark J. Lehman

unread,
Aug 14, 2014, 2:17:35 PM8/14/14
to jquery-f...@googlegroups.com
Did you ever find a solution to this? I too have done this with carrierwave but cannot figure out how to get the actual file type to transfer as the content type with just the jQuery File Upload plugin.

I managed to change it so that all files uploaded now are set to Content-Type: image/jpeg on S3. That may help you, but it doesn't help me, as I now have PDFs and MP3 files that, when uploaded, show up in S3 as Content-Type: image/jpeg.

Anyway, I basically followed the tutorial on heroku for the initial setup, but changed the instance variable in my controller to this:

    @s3_direct_post = S3_BUCKET.presigned_post(
                      key: "uploads/#{SecureRandom.uuid}/${filename}",
                      success_action_status: 201,
                      acl: :public_read,
                      content_type: "").where(:content_type).starts_with("")

(Bold part is what I added.) Don't ask me why, but this change makes every file I upload default to image/jpeg file type.

Please let me know if you found a solution that uploads the ACTUAL content type.

Alex B

unread,
Aug 14, 2014, 3:45:03 PM8/14/14
to jquery-f...@googlegroups.com
Sorry, no.

I am lucky to have Carrierwave do it for me during post-processing (thanks to the two lines I mentioned on July 22nd).

If you ever find a way, please post it here - I am sure many people would benefit.

Mark J. Lehman

unread,
Aug 14, 2014, 3:53:24 PM8/14/14
to jquery-f...@googlegroups.com
Will do. I posted to stackoverflow as well, so hopefully somebody jumps in to help:


Mark J. Lehman


--
You received this message because you are subscribed to a topic in the Google Groups "jQuery-File-Upload" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jquery-fileupload/MM2E9OFWev4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jquery-fileupl...@googlegroups.com.
To post to this group, send email to jquery-f...@googlegroups.com.
Visit this group at http://groups.google.com/group/jquery-fileupload.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages