Uploading Videos to S3 with Carrierwave and Fog

2019-09-18 17:26发布

I have configured my testapp with Carrierwave and Fog. My goal is to upload videos to Amazon S3 but if I try to upload a video I get an error "pipe broken". It works if I'm just uploading a picture, so my Amazon configs should be ok!

Does carrierwave works for videos? Or why does it work for images and not for videos?

Carrierwave.rb:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => 'XXX',
    :aws_secret_access_key  => 'YYY'

  }
  config.fog_directory  = 'testbucket'
end

Video_Uploader.rb:

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

upload_form:

<%= form_for @video do |f| %>
    <div class="field">
      <%= f.label :name %><br />
      <%= f.text_field :name %>
    </div>
    <div class="field">
      <%= f.file_field :video %>
    </div>
    <div class="actions">
      <%= f.submit %>
    </div>
<% end %>

Controller:

def create
  @video = Video.new(params[:video])
    if @video.save
    redirect_to videos_url
  else
    render :new
  end
end

0条回答
登录 后发表回答