1

每当我尝试使用我的 Rails 应用上传视频时

显示以下错误:

ArgumentError (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
  app/uploaders/media_uploader.rb:64:in `zencode'
  app/controllers/profile/videos_controller.rb:63:in `create'

顺便说一下,我正在使用 Zencoder 和 Carrierwave

这是我的 media_uploader.rb

# encoding: utf-8

class MediaUploader < CarrierWave::Uploader::Base
    include Rails.application.routes.url_helpers
    Rails.application.routes.default_url_options = ActionMailer::Base.default_url_options

  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  # include CarrierWave::MiniMagick

  # Choose what kind of storage to use for this uploader:
  #storage :file
    after :store, :zencode
    storage :fog


  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end


    def cache_dir
        "#{Rails.root}/tmp/uploads"
    end

  # Provide a default URL as a default if there hasn't been a file uploaded:
  # def default_url
  #   "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  # end

  # Process files as they are uploaded:
  # process :scale => [200, 300]
  #
  # def scale(width, height)
  #   # do something
  # end

  # Create different versions of your uploaded files:
  # version :thumb do
  #   process :scale => [50, 50]
  # end

  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
   def extension_white_list
     %w(mp4 flv ogv avi)
   end

  # Override the filename of the uploaded files:
  # Avoid using model.id or version_name here, see uploader/store.rb for details.
   def filename
     #"video.mp4" if original_filename
        "video.mp4"
   end

    private
    def zencode(args)
        zencoder_response = Zencoder::Job.create({:input => "s3://peekbox.s3.amazonaws.com/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}/video.mp4",
                                                                                            :outputs => [{:base_url => "s3://peekbox.s3.amazonaws.com/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{@model.id}",
                                                                                                                         :filename => "video.mp4",
                                                                                                                         :label => "web",
                                                                                                                         :notifications => [zencoder_callback_url(:protocol => "http", :host => ENV['URL'], :port => ENV['PORT'])],
                                                                                                                         :video_codec => "h264",
                                                                                                                         :audio_codec => "aac",
                                                                                                                         :quality => 3,
                                                                                                                         :width => 854,
                                                                                                                         :height => 480,
                                                                                                                         :format => "mp4",
                                                                                                                         :aspect_mode => "preserve",
                                                                                                                         :public => 1,
                                                                                                                            :thumbnails => {:base_url => "s3://peekbox.s3.amazonaws.com/uploads/#{model.class.to_s.underscore}/thumb/#{mounted_as}/#{@model.id}",
                                                                                                                            :width => 200,
                                                                                                                            :height => 114,
                                                                                                                            :aspect_mode => "crop",
                                                                                                                            :number => 10,
                                                                                                                            :filename => "{{number}}_{{width}}x{{height}}-thumbnail"}}]
                                              }) 



        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

顺便说一句,我不知道这是否与我从 Heroku 迁移到 AWS Ec2 有关?请帮忙。

编辑:

每当我尝试设置这条线

:notifications => [zencoder_callback_url(:protocol => "http", :host => ENV['URL'], :port => ENV['PORT'])],

进入

:notifications => [zencoder_callback_url(:protocol => "http", :host => 'peekbox.tv', :port => ENV['PORT'])],

它有不同的错误 w/c 是

   NoMethodError (undefined method `each' for nil:NilClass):
      app/uploaders/media_uploader.rb:83:in `zencode'
      app/controllers/profile/videos_controller.rb:63:in `create'
4

1 回答 1

1

您应该在中添加以下选项config/production.rb

config.action_mailer.default_url_options = { host: 'peekbox.tv' }
于 2013-02-07T11:47:12.807 回答