1

I am doing a video upload with Carrierwave, and it keeps failing. But the log doesn't show me what's wrong.

This is my video_uploader.rb:

class VideoUploader < CarrierWave::Uploader::Base    
  storage :fog

  def content_type_whitelist
    /video\//
  end

  def extension_whitelist
    %w(mp4 mov wmv mpeg4 avi 3gpp webm)
  end    
end

This is what my log looks like of the successful update action (which includes the new file to be uploaded):

Started PATCH "/profiles/kristin-walter-jamaica-college" for ::1 at 2016-10-19 05:22:56 -0500
Processing by ProfilesController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"YBrqV==", "profile"=>{"remove_avatar"=>"0", "avatar_cache"=>"", "first_name"=>"Kristin", "last_name"=>"Walter", "dob(3i)"=>"1", "dob(2i)"=>"5", "dob(1i)"=>"1998", "weight"=>"249", "height"=>"85", "bib_color"=>"19", "player_type"=>"player", "video_url"=>"https://www.youtube.com/embed/a4k", "position_ids"=>[""], "school_id"=>"2", "grade"=>"", "grades_attributes"=>{"0"=>{"subject"=>"", "result"=>"", "grade_type"=>"csec", "_destroy"=>"false"}}, "transcript_cache"=>"", "achievements_attributes"=>{"0"=>{"body"=>"", "achievement_type"=>"academic", "_destroy"=>"false"}}, "videos_attributes"=>{"0"=>{"url"=>"", "remove_video"=>"0", "video"=>#<ActionDispatch::Http::UploadedFile:0x007fbccc812f28 @tempfile=#<Tempfile:/var/folders/0f/hgplttnd7dg6q9m62qtbnpn00000gn/T/RackMultipart20161019-12863-159wlxq.MOV>, @original_filename="P8250323.MOV", @content_type="video/quicktime", @headers="Content-Disposition: form-data; name=\"profile[videos_attributes][0][video]\"; filename=\"P8250323.MOV\"\r\nContent-Type: video/quicktime\r\n">, "video_cache"=>"", "vimeo_url"=>"", "vimeo_embed_code"=>"", "official"=>"", "_destroy"=>"false", "id"=>"4"}, "1"=>{"url"=>"", "remove_video"=>"0", "video_cache"=>"", "vimeo_url"=>"", "vimeo_embed_code"=>"", "official"=>"", "_destroy"=>"false"}}, "articles_attributes"=>{"0"=>{"source"=>"Gleaner", "title"=>"JC Off The Mark With Easy Win", "url"=>"http://jamaica-gleaner.com/article/sports/20160911/jc-mark-easy-win", "_destroy"=>"false", "id"=>"1"}, "1"=>{"source"=>"", "title"=>"", "url"=>"", "_destroy"=>"false"}}}, "commit"=>"Update Profile", "id"=>"kristin-walter-jamaica-college"}
  Profile Load (1.2ms)  SELECT  "profiles".* FROM "profiles" WHERE "profiles"."slug" = $1 ORDER BY "profiles"."id" ASC LIMIT $2  [["slug", "kristin-walter-jamaica-college"], ["LIMIT", 1]]
  Grade Load (1.0ms)  SELECT "grades".* FROM "grades" WHERE "grades"."profile_id" = 9
  HABTM_Positions Load (1.0ms)  SELECT "positions_profiles".* FROM "positions_profiles" WHERE "positions_profiles"."profile_id" = 9
  Achievement Load (1.0ms)  SELECT "achievements".* FROM "achievements" WHERE "achievements"."profile_id" = 9
   (0.9ms)  SELECT COUNT(*) FROM "videos" WHERE "videos"."profile_id" = $1  [["profile_id", 9]]
   (0.6ms)  BEGIN
  Position Load (1.1ms)  SELECT "positions".* FROM "positions" WHERE 1=0
  Article Load (1.1ms)  SELECT "articles".* FROM "articles" WHERE "articles"."profile_id" = $1 AND "articles"."id" = 1  [["profile_id", 9]]
  Video Load (1.9ms)  SELECT "videos".* FROM "videos" WHERE "videos"."profile_id" = $1 AND "videos"."id" = 4  [["profile_id", 9]]
  SQL (3.3ms)  UPDATE "profiles" SET "updated_at" = $1, "avatar" = $2 WHERE "profiles"."id" = $3  [["updated_at", 2016-10-19 10:22:56 UTC], ["avatar", "Recrutz-6.jpg"], ["id", 9]]
   (78.2ms)  COMMIT
Redirected to http://localhost:3000/profiles/kristin-walter-jamaica-college
Completed 302 Found in 126ms (ActiveRecord: 91.2ms)

This my Video.rb model:

class Video < ApplicationRecord
  mount_uploader :video, VideoUploader
  belongs_to :profile
end

This is my profile_controller#update.rb, which is where the associated video object is being uploaded from:

  def update    
    respond_to do |format|
      if @profile.update(profile_params)
        format.html { redirect_to @profile, notice: 'Profile was successfully updated.' }
        format.json { render :show, status: :ok, location: @profile }
      else
        format.html { redirect_to edit_profile_path(@profile), message: @profile.errors.messages }
        format.json { render json: @profile.errors, status: :unprocessable_entity }
      end
    end
  end

This is the relevant portion of the _form.html.erb:

  <h3 class="text-center">Videos</h3>

  <div id="videos" class="text-center">
    <%= f.simple_fields_for :videos do |video| %>
      <%= render 'video_fields', f: video %>
    <% end %>
    <div class="links">
      <%= link_to_add_association 'Add Video', f, :videos, class: "btn btn-success add-grade-button" %>
    </div>
  </div>

This is the _video_fields.html.erb partial referenced in the _form partial (truncated for brevity):

          <%= f.input_field :url, class: 'form-control' %>
            <% if !@profile.videos.empty? %>
              <% @profile.videos.each do |video| %>
                <%= video.video_identifier %>
                <label>
                  <%= f.check_box :remove_video %>
                  Remove video
                </label>
              <% end %>
            <% end %>
            <%= f.file_field :video, class: 'form-control' %>
            <%= f.input_field :video_cache, as: :hidden, class: 'form-control '%>
           <%= f.input_field :vimeo_url, class: 'form-control' %>
           <%= f.input_field :vimeo_embed_code, class: 'form-control' %>
    <%= f.input_field :official, as: :radio_buttons, class: 'form-control' %>        
      <% end %>

I have two other uploaders for images & documents, and they work fine. For some reason, this one doesn't work.

It creates the folder on S3, but it doesn't actually upload the file.

How do I troubleshoot this?

Edit 1

In my profile.rb model, I have the following:

  has_many :videos, dependent: :destroy
  accepts_nested_attributes_for :videos, reject_if: :reject_videos, allow_destroy: true

Edit 2

This is the log output when I upload a file that should NOT work, i.e. an image in the video upload. Nothing obvious happens. It just fails silently.

Started PATCH "/profiles/kristin-walter-jamaica-college" for ::1 at 2016-10-20 02:21:37 -0500
Processing by ProfilesController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"390ImtDcSl4RoEZA==", "profile"=>{"remove_avatar"=>"0", "avatar_cache"=>"", "first_name"=>"Kristin", "last_name"=>"Walter", "dob(3i)"=>"1", "dob(2i)"=>"5", "dob(1i)"=>"1998", "weight"=>"249", "height"=>"85", "bib_color"=>"19", "player_type"=>"player", "video_url"=>"https://www.youtube.com/embed/Rpa4k", "position_ids"=>[""], "school_id"=>"2", "grade"=>"", "grades_attributes"=>{"0"=>{"subject"=>"", "result"=>"", "grade_type"=>"csec", "_destroy"=>"false"}}, "transcript_cache"=>"", "achievements_attributes"=>{"0"=>{"body"=>"", "achievement_type"=>"academic", "_destroy"=>"false"}}, "videos_attributes"=>{"0"=>{"url"=>"", "remove_video"=>"0", "video"=>#<ActionDispatch::Http::UploadedFile:0x007fdff5b64c48 @tempfile=#<Tempfile:/var/folders/0f/hgplttnd7dg6q9m62qtbnpn00000gn/T/RackMultipart20161020-27906-95t0fg.jpg>, @original_filename="Photo Oct 13, 3 36 47 PM.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"profile[videos_attributes][0][video]\"; filename=\"Photo Oct 13, 3 36 47 PM.jpg\"\r\nContent-Type: image/jpeg\r\n">, "video_cache"=>"", "vimeo_url"=>"", "vimeo_embed_code"=>"", "official"=>"", "_destroy"=>"false", "id"=>"4"}, "1"=>{"url"=>"", "remove_video"=>"0", "video_cache"=>"", "vimeo_url"=>"", "vimeo_embed_code"=>"", "official"=>"", "_destroy"=>"false"}}, "articles_attributes"=>{"0"=>{"source"=>"Gleaner", "title"=>"JC Off The Mark With Easy Win", "url"=>"http://jamaica-gleaner.com/article/sports/20160911/jc-mark-easy-win", "_destroy"=>"false", "id"=>"1"}, "1"=>{"source"=>"", "title"=>"", "url"=>"", "_destroy"=>"false"}}}, "commit"=>"Update Profile", "id"=>"kristin-walter-jamaica-college"}
  Profile Load (1.1ms)  SELECT  "profiles".* FROM "profiles" WHERE "profiles"."slug" = $1 ORDER BY "profiles"."id" ASC LIMIT $2  [["slug", "kristin-walter-jamaica-college"], ["LIMIT", 1]]
  Grade Load (0.8ms)  SELECT "grades".* FROM "grades" WHERE "grades"."profile_id" = 9
  HABTM_Positions Load (1.1ms)  SELECT "positions_profiles".* FROM "positions_profiles" WHERE "positions_profiles"."profile_id" = 9
  Achievement Load (1.0ms)  SELECT "achievements".* FROM "achievements" WHERE "achievements"."profile_id" = 9
   (0.8ms)  SELECT COUNT(*) FROM "videos" WHERE "videos"."profile_id" = $1  [["profile_id", 9]]
   (1.0ms)  BEGIN
  Position Load (1.2ms)  SELECT "positions".* FROM "positions" WHERE 1=0
  Article Load (1.0ms)  SELECT "articles".* FROM "articles" WHERE "articles"."profile_id" = $1 AND "articles"."id" = 1  [["profile_id", 9]]
  Video Load (0.9ms)  SELECT "videos".* FROM "videos" WHERE "videos"."profile_id" = $1 AND "videos"."id" = 4  [["profile_id", 9]]
  SQL (1.9ms)  UPDATE "profiles" SET "updated_at" = $1, "avatar" = $2 WHERE "profiles"."id" = $3  [["updated_at", 2016-10-20 07:21:37 UTC], ["avatar", "Recrutz-6.jpg"], ["id", 9]]
   (111.8ms)  COMMIT
Redirected to http://localhost:3000/profiles/kristin-walter-jamaica-college
Completed 302 Found in 151ms (ActiveRecord: 122.6ms)

Edit 3

As a point of comparison, here is the log from the update operation of a successful avatar upload -- note this is governed by a different model, and different uploader, etc. But just to show what the log looks like when it actually uploads successfully.

Started PATCH "/profiles/kristin-walter-jamaica-college" for ::1 at 2016-10-20 05:52:41 -0500
Processing by ProfilesController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"RqAORU3Iw==", "profile"=>{"avatar"=>#<ActionDispatch::Http::UploadedFile:0x007fdff618de58 @tempfile=#<Tempfile:/var/folders/0f/hgplttnd7dg6q9m62qtbnpn00000gn/T/RackMultipart20161020-27906-1cg2dxq.jpg>, @original_filename="DSC_0010.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"profile[avatar]\"; filename=\"DSC_0010.jpg\"\r\nContent-Type: image/jpeg\r\n">, "avatar_cache"=>"", "first_name"=>"Kristin", "last_name"=>"Walter", "dob(3i)"=>"1", "dob(2i)"=>"5", "dob(1i)"=>"1998", "weight"=>"249", "height"=>"85", "bib_color"=>"19", "player_type"=>"player", "video_url"=>"https://www.youtube.com/Rpa4k", "position_ids"=>[""], "school_id"=>"2", "grade"=>"", "grades_attributes"=>{"0"=>{"subject"=>"", "result"=>"", "grade_type"=>"csec", "_destroy"=>"false"}}, "transcript_cache"=>"", "achievements_attributes"=>{"0"=>{"body"=>"", "achievement_type"=>"academic", "_destroy"=>"false"}}, "videos_attributes"=>{"0"=>{"url"=>"", "remove_video"=>"0", "video_cache"=>"", "vimeo_url"=>"", "vimeo_embed_code"=>"", "official"=>"", "_destroy"=>"false", "id"=>"4"}, "1"=>{"url"=>"", "remove_video"=>"0", "video_cache"=>"", "vimeo_url"=>"", "vimeo_embed_code"=>"", "official"=>"", "_destroy"=>"false"}}, "articles_attributes"=>{"0"=>{"source"=>"Gleaner", "title"=>"JC Off The Mark With Easy Win", "url"=>"http://jamaica-gleaner.com/article/sports/20160911/jc-mark-easy-win", "_destroy"=>"false", "id"=>"1"}, "1"=>{"source"=>"", "title"=>"", "url"=>"", "_destroy"=>"false"}}}, "commit"=>"Update Profile", "id"=>"kristin-walter-jamaica-college"}
  Profile Load (1.3ms)  SELECT  "profiles".* FROM "profiles" WHERE "profiles"."slug" = $1 ORDER BY "profiles"."id" ASC LIMIT $2  [["slug", "kristin-walter-jamaica-college"], ["LIMIT", 1]]
  Grade Load (1.0ms)  SELECT "grades".* FROM "grades" WHERE "grades"."profile_id" = 9
  HABTM_Positions Load (1.3ms)  SELECT "positions_profiles".* FROM "positions_profiles" WHERE "positions_profiles"."profile_id" = 9
  Achievement Load (1.0ms)  SELECT "achievements".* FROM "achievements" WHERE "achievements"."profile_id" = 9
   (0.9ms)  SELECT COUNT(*) FROM "videos" WHERE "videos"."profile_id" = $1  [["profile_id", 9]]
   (0.6ms)  BEGIN
  Position Load (0.8ms)  SELECT "positions".* FROM "positions" WHERE 1=0
  Article Load (1.4ms)  SELECT "articles".* FROM "articles" WHERE "articles"."profile_id" = $1 AND "articles"."id" = 1  [["profile_id", 9]]
  Video Load (1.3ms)  SELECT "videos".* FROM "videos" WHERE "videos"."profile_id" = $1 AND "videos"."id" = 4  [["profile_id", 9]]
  SQL (2.3ms)  UPDATE "profiles" SET "avatar" = $1, "updated_at" = $2 WHERE "profiles"."id" = $3  [["avatar", "DSC_0010.jpg"], ["updated_at", 2016-10-20 10:52:41 UTC], ["id", 9]]
   (1.3ms)  COMMIT
Redirected to http://localhost:3000/profiles/kristin-walter-jamaica-college
Completed 302 Found in 1053ms (ActiveRecord: 13.4ms)
marcamillion
  • 32,933
  • 55
  • 189
  • 380
  • Are you using the AWS transcoder with your video upload? Also the error might not be on your apps side so it might not be in your log file, what does the response from s3 say? – C dot StrifeVII Oct 19 '16 at 12:39
  • @CdotStrifeVII How can I see the response from S3? I am not using AWS transcoder. I am just trying to do a plain, vanilla, file upload. – marcamillion Oct 19 '16 at 12:43
  • Hmmm this is a tough one. Normally I upload to s3 directly not through carrier wave so I usually get the response directly from AWS, I am not too sure how to get it with carrierwave. If it is creating the file on S3 then we know its communicating with it, I am assuming this issue may be with the actual video itself. Are you sure its of the approve white listed extensions? Did you try different videos? – C dot StrifeVII Oct 19 '16 at 13:06
  • I just tried modifying the whitelist rules to `"video/quicktime"`, which is what Carrierwave tells me that filetype is in the log, and it still doesn't work. That original file was 69MB (MOV), and I just tried one that is 48MB (mov) and neither worked. So I doubt it is the files. I am sure the extension is allowed, because I allowed it! Now that I think about it, the one thing I didn't do was restart my server after I created this new uploader...I don't think. Lemme try that. – marcamillion Oct 19 '16 at 13:51
  • Nope...that didn't work :( What is interesting though is that when I am looking through the logs, I am not seeing an `insert` statement for creating a new `Video` record. Could that be, because Rails doesn't save the record if the upload didn't complete properly? If you look at the log above, notice there is only a `SELECT "videos"` statement. – marcamillion Oct 19 '16 at 13:54
  • Yes if the upload is not going through the record would not save but I don't know why that would not leave some sort of tell, like you should get back a 400 or 500 error code somewhere. Thats is one reason I avoid gems when I can because they can be a pain to trouble shoot because you don't know exactly where things are happening. Can you post the out put of when you do one of these failed uploads? – C dot StrifeVII Oct 19 '16 at 14:05
  • @CdotStrifeVII I updated the question. The `tl;dr` version is that the log output looks similar, i.e. it looks like it successfully uploaded when it shouldn't have, which I guess is telling in and of itself. – marcamillion Oct 20 '16 at 07:24
  • Yea man I got nothing at the moment, I will look around and see if I can find something – C dot StrifeVII Oct 20 '16 at 11:28
  • @CdotStrifeVII I suspect it may be related to this: http://stackoverflow.com/questions/40161319/uploading-via-a-nested-form-and-carrierwave-doesnt-seem-to-be-working Thoughts on either? – marcamillion Oct 20 '16 at 17:55

0 Answers0