Note that there are some explanatory texts on larger screens.

plurals
  1. POsetting content-type for mp4 files on s3
    primarykey
    data
    text
    <p>I am adding user uploaded videos to my RoRs site with the help of the paperclip gem and s3 storage. For some reason that I can't figure out, whenever a user uploads an mp4 file, s3 sets content-type for that file as <code>application/mp4</code> instead of <code>video/mp4</code>. </p> <p>Note that I have registered mp4 mime type in an initializer file:</p> <p><code>Mime::Type.lookup_by_extension('mp4').to_s =&gt; "video/mp4"</code></p> <p>Here is the relevant part of my Post model:</p> <pre><code> has_attached_file :video, :storage =&gt; :s3, :s3_credentials =&gt; "#{Rails.root.to_s}/config/s3.yml", :path =&gt; "/video/:id/:filename" validates_attachment_content_type :video, :content_type =&gt; ['video/mp4'], :message =&gt; "Sorry, this site currently only supports MP4 video" </code></pre> <p>What am I missing in my paperclip and/or s3 set-up.</p> <p><strong>####Update#####</strong></p> <p>For some reason that is beyond my knowledge of Rails, my default mime types for mp4 contained files is the following:</p> <pre><code> MIME::Types.type_for("my_video.mp4").to_s =&gt; "[application/mp4, audio/mp4, video/mp4, video/vnd.objectvideo]" </code></pre> <p>So, when paperclip send an mp4 file to s3, it seems to identify the file's mime type as the first default, "application/mp4". That is why s3 identifies the file as having a content-type of "application/mp4". Because I want to enable streaming of these mp4 files, I need paperclip to identify the file as having a mime type of "video/mp4". </p> <p>Is there a way to modify paperclip (maybe in a before_post_process filter) to allow for this, or is there a way to modify rails through an init file to identify mp4 files as being "video/mp4". If I could do either, which way is best.</p> <p>Thanks for your help</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload