如果没有错误发送到日志,如何解决失败的视频上传(Carrierwave)问题?

时间:2016-10-19 10:30:35

标签: ruby-on-rails file-upload amazon-s3 carrierwave ruby-on-rails-5

我正在使用Carrierwave进行视频上传,但它一直在失败。但日志并没有告诉我什么是错的。

这是我的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

这是我的日志看起来成功的更新操作(包括要上传的新文件):

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)

这是我的Video.rb型号:

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

这是我的profile_controller#update.rb,它是从中上传关联的video对象的位置:

  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

这是_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>

这是_video_fields.html.erb部分引用的_form部分(为简洁而截断):

          <%= 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 %>

我有两个其他上传者用于图像&amp;文件,他们工作正常。出于某种原因,这个没有用。

它在S3上创建文件夹,但它实际上并没有上传文件。

如何解决此问题?

修改1

在我的profile.rb模型中,我有以下内容:

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

修改2

这是我上传不应该工作的文件时的日志输出,即视频上传中的图像。没有明显的事情发生。它只是默默无闻。

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)

编辑3

作为比较点,这里是成功的头像上传的更新操作的日志 - 注意这是由不同的模型,不同的上传者等管理。但只是为了显示日志的样子实际上传成功。

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)

0 个答案:

没有答案