2017-04-08 147 views
1

我已經經歷了所有答案,使我的視頻上傳到S3工作,但他們不工作。我繼續得到錯誤未初始化的常量Paperclip :: Storage :: S3 :: Aws。上傳視頻Rails/S3/Paperclip

我希望你能幫我解決這個問題。

的Gemfile

gem 'simple_form', '~> 3.4' 
gem 'haml', '~> 4.0', '>= 4.0.7' 
gem 'coffee-script-source', '1.8.0' 
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.7' 
gem 'paperclip' 
gem 'carrierwave' 
gem "paperclip-ffmpeg", "~> 1.0.1" 
gem 'paperclip-av-transcoder' 
gem 'aws-sdk', '~> 1.6' 
gem "figaro" 

配置\ s3.yml

AWS_ACCESS_KEY_ID: xxx 
    AWS_SECRET_ACCESS_KEY: xxx 
    S3_BUCKET_NAME: xxx 

型號\ video.rb

class Video < ApplicationRecord 

      has_attached_file :clip, styles: { 
         medium: { 
            :geometry => "640x480", 
            :format => 'mp4' 
         }, 
         thumb: { :geometry => "160x120", 
            :format => 'jpeg', 
            :time => 10} 
         }, 

         processors: [:transcoder], 

          :storage => :s3, 
          :s3_credentials => "#{Rails.root}/config/s3.yml" 


      validates_attachment :clip, 
        content_type: { content_type: ['application/x-shockwave-flash', 'application/x-shockwave-flash', 'application/flv', 'video/x-flv']} 


      before_post_process :skip_for_audio 

      def skip_for_audio 
       ! %w(audio/ogg application/ogg).include?(asset_content_type) 
      end 

      before_post_process :image? 
      def image? 
       !(data_content_type =~ /^image.*/).nil? 
      end 
end 

個Videos_controller.rb

class VideosController < ApplicationController 


     def index 
     @videos = Video.all 
     @video = Video.order('created_at') 
     end 

     def new 
     @video = Video.new 
     end 


     def create 
     @video = Video.new(videos_params) 
     if @video.save 
      flash[:success] = "The step was added!" 
      redirect_to root_path 
     else 
      render 'New' 
     end 

     end 

     def destroy 
      @video = Video.find(params[:id]) 
      @video.destroy 
      flash[:success] = "The step was destroyed." 
      redirect_to root_path 
     end 

     private 

     def videos_params 
      params.require(:video).permit(:title, :description, :clip) 
     end 




    end 

initilizers \ paperclip.rb

paperclip_defaults = Rails.application.config_for :paperclip 
paperclip_defaults.symbolize_keys! 

Paperclip::Attachment.default_options.merge! paperclip_defaults 

initilizers \ aws.rb

AWS.config(
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'], 
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] 
) 

S3_BUCKET = AWS::S3.new.buckets[ENV['S3_BUCKET']] 
+1

您的回形針和AWS的初始化工具的外觀如何? –

+0

這是回形針 paperclip_defaults = Rails.application.config_for:paperclip paperclip_defaults.symbolize_keys! Paperclip :: Attachment.default_options.merge! paperclip_defaults 而這是一個用於AWS AWS.config( :access_key_id => ENV [ 'AWS_ACCESS_KEY_ID'], :secret_access_key => ENV [ 'AWS_SECRET_ACCESS_KEY'] ) S3_BUCKET = AWS :: S3。 new.buckets [ENV ['S3_BUCKET']] –

+0

你能用回形針默認配置更新你的問題嗎? – catch22

回答

0

有你試過this configuration

# config/environments/production.rb 
config.paperclip_defaults = { 
    storage: :s3, 
    s3_credentials: { 
    bucket: ENV.fetch('S3_BUCKET_NAME'), 
    access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'), 
    secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'), 
    s3_region: ENV.fetch('AWS_REGION'), 
    } 
} 

# config/initializers/paperclip.rb 
Paperclip::Attachment.default_options[:url] = ':s3_domain_url' 
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename' 
Paperclip::Attachment.default_options[:s3_host_name] = 's3-us-west-2.amazonaws.com' 

+0

我實際上是在追查你的建議,但現在我收到這個錯誤 '運行命令時出錯if command -v avprobe 2>/dev/null;然後回顯「真實」;其他回聲「假」; fi:命令'if command -v avprobe 2>/dev/null;然後回顯「真實」;其他回聲「假」; fi'返回1.預期0這是命令輸出:STDOUT:STDERR:-v此時意外。 ' –

+0

對不起,我不熟悉這個錯誤。你在哪裏得到它?你有這個github回購嗎? – catch22

+0

是的 - https://github.com/Stepeo/Redam - 如果你能解釋我發生了什麼,這將是非常棒的! :) –