Carrierwave_Direct + Rails问题

时间:2017-05-09 09:27:06

标签: ruby-on-rails ruby amazon-s3 carrierwave carrierwave-direct

video_uploader.rb

class VideoUploader < CarrierWave::Uploader::Base
  include CarrierWaveDirect::Uploader
  alias_method :extension_white_list, :extension_whitelist
  def will_include_content_type
    true
  end
  default_content_type  'video/mp4'
  allowed_content_types %w(video/mpeg video/mp4 video/ogg)
end

Model.rb

class Video < ActiveRecord::Base
  mount_uploader :videosub, VideoUploader
end

参数:

"videosub"=>#<ActionDispatch::Http::UploadedFile:0x007f87201e28 @tempfile=#<Tempfile:/tmp/RackMultipart20170509-4704-1mjrwq.mp4>, @original_filename="168C7704-4337-A870-007B2CB22519.mp4", @content_type="video/mp4

错误显示是:

Validation failed: Videosub is invalid. 

如果我将VideoUploader中的代码替换为:

class VideoUploader < CarrierWave::Uploader::Base
  include CarrierWaveDirect::Uploader
  alias_method :extension_white_list, :extension_whitelist
  storage :fog 
end

然后该文件正在成功上传到S3。但在我的情况下,我需要在后台上传视频并直接上传到绕过应用程序托管服务器的S3。

请帮忙!

1 个答案:

答案 0 :(得分:0)

找到解决方案: 之前我通过定义repo的github路径来包含gem。后来我刚刚消除了这条路。它奏效了。