2012-07-30 67 views
2

我下面這個教程Zencoder納入我的Rails應用程序3:http://www.nickdesteffen.com/blog/video-encoding-with-uploadify-carrierwave-and-zencoderRails 3:如何配置Zencoder以使用Amazon S3?

本教程使用Rackspace的存儲,但我想適應的代碼,這樣我可以使用Amazon S3存儲來代替。我用我的Amazon S3信息替換了所有Rackspace信息,但每當我嘗試上載視頻時,都會收到以下HTTP錯誤:「您嘗試上傳的文件出現錯誤。請確認它是正確的類型「。

我需要在此修復以完成此項工作?

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 

回答

相關問題