首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >上传视频Rails/S3/剪纸

上传视频Rails/S3/剪纸
EN

Stack Overflow用户
提问于 2017-04-08 13:52:09
回答 1查看 1K关注 0票数 1

我已经通过了所有的答案,使我的视频上传到S3工作,但他们不工作。我继续获取未初始化的常量剪贴纸::Storage::S3::Aws的错误。

我希望你能在这件事上帮我。

Gemfile

代码语言:javascript
复制
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

代码语言:javascript
复制
 AWS_ACCESS_KEY_ID: xxx
    AWS_SECRET_ACCESS_KEY: xxx
    S3_BUCKET_NAME: xxx

models\video.rb

代码语言:javascript
复制
    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

代码语言:javascript
复制
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

代码语言:javascript
复制
paperclip_defaults = Rails.application.config_for :paperclip
paperclip_defaults.symbolize_keys!

Paperclip::Attachment.default_options.merge! paperclip_defaults

initilizers\aws.rb

代码语言:javascript
复制
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']]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-08 15:40:16

你试过这种配置了吗

代码语言:javascript
复制
# 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'),
  }
}

代码语言:javascript
复制
# 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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43294947

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档