Rails 3: How to configure Zencoder to work with Amazon S3?

1.7k views Asked by At

I'm following this tutorial to integrate Zencoder in my Rails 3 app: http://www.nickdesteffen.com/blog/video-encoding-with-uploadify-carrierwave-and-zencoder

The tutorial uses Rackspace for storage, but I'd like to adapt the code so that I can use Amazon S3 for storage instead. I replaced all the Rackspace info with my Amazon S3 info, but whenever I try to upload a video in my form, I get this HTTP error: "There was an error with the file you tried uploading.Please verify that it is the correct type."

What do I need to fix here to make this work?

carrierwave.rb

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => 'xxx',
    :aws_secret_access_key  => 'xxx',
  }
  config.fog_directory  = 'mybucket'
  config.fog_public     = true
  config.fog_attributes = {'Cache-Control' => 'max-age=315576000'}
end

video_uploader.rb

class VideoUploader < CarrierWave::Uploader::Base
  include Rails.application.routes.url_helpers

  Rails.application.routes.default_url_options = ActionMailer::Base.default_url_options

  after :store, :zencode

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def extension_white_list
    %w(mov avi mp4 mkv wmv mpg)
  end

  def filename
    "video.mp4" if original_filename
  end

  private 

  def zencode(args)
    zencoder_response = Zencoder::Job.create({:input => 's3://mybucket/key.mp4',
                      :outputs => [{:label => 'vp8 for the web',
                                    :url => 's3://mybucket/key_output.webm'}]})

    zencoder_response.body["outputs"].each do |output|
      if output["label"] == "web"
        @model.zencoder_output_id = output["id"]
        @model.processed = false
        @model.save(:validate => false)
      end
    end
  end

end
1

There are 1 answers

0
GreenEggs On

I've been working on the same issue.

Using Fog for my credentials I created my urls like so:

bucket = AttachmentUploader.fog_directory
input = "s3://#{bucket}/#{self.path}"
base_url = "s3://#{bucket}/#{store_dir}"

Take a look at my gist for more detail: https://gist.github.com/4002368

Don't forget to allow Zencoder to acces your bucket via security policy: https://app.zencoder.com/docs/guides/getting-started/working-with-s3