我正在按照本教程将 Zencoder 集成到我的 Rails 3 应用程序中:http: //www.nickdesteffen.com/blog/video-encoding-with-uploadify-carrierwave-and-zencoder
本教程使用 Rackspace 进行存储,但我想修改代码以便可以使用 Amazon S3 进行存储。我用我的 Amazon S3 信息替换了所有 Rackspace 信息,但是每当我尝试在表单中上传视频时,我都会收到以下 HTTP 错误:“您尝试上传的文件出错。请验证它是正确的类型。”
我需要在这里修复什么才能完成这项工作?
载波.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