2012-07-30 59 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 

回答

相关问题