简体   繁体   中英

Uploading video with Rails/Paperclip to Heroku/S3

I've been failing at uploading a video in production mode on Heroku for way too long, testing local works great with resizing and thumbnail creation. Images also work fine going to my S3 bucket, so the credentials are all okay.

Here are the logs I usually get from the code used below. Incidentally, the attempt right before I got these logs (without changing any code and using the same test video), the video made it to AWS, just without the resizing or thumbnail creation. But that was the only time I have even made it that far, and this failed upload and 500 error immediately happened after.

$ heroku logs

2015-08-06T15:38:39.732913+00:00 app[web.1]: Started POST "/work/create" for 104.162.101.0 at 2015-08-06 15:38:39 +0000
2015-08-06T15:38:39.696998+00:00 app[web.1]: source=rack-timeout id=dd06eb06-cad5-4236-8788-e5f59f7fe631 wait=7850ms timeout=15000ms service=0ms state=active
2015-08-06T15:38:39.734677+00:00 app[web.1]: Processing by WorksController#create as HTML
2015-08-06T15:38:39.734744+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"9edyQVZm68aW+majARmNcDR1dwpE59ZrWEZ4/G07ADYhlZyYiJ+RwYK4GBguQZbrlS6J4yDbMsMIxcvWLD3aUA==", "work"=>{"position"=>"", "media_type"=>"video", "video"=>#<ActionDispatch::Http::UploadedFile:0x007efee96e14e8 @tempfile=#<Tempfile:/tmp/RackMultipart20150806-3-1mu6ibh.mp4>, @original_filename="FA14 final_compilation_mg4d_H.264.mp4", @content_type="video/mp4", @headers="Content-Disposition: form-data; name=\"work[video]\"; filename=\"FA14 final_compilation_mg4d_H.264.mp4\"\r\nContent-Type: video/mp4\r\n">, "designer"=>""}}
2015-08-06T15:38:40.030596+00:00 heroku[router]: at=info method=POST path="/work/create" host=purchasedesign.herokuapp.com request_id=dd06eb06-cad5-4236-8788-e5f59f7fe631 fwd="104.162.101.0" dyno=web.1 connect=1ms service=8181ms status=500 bytes=192
2015-08-06T15:38:40.017315+00:00 app[web.1]: Command :: file -b --mime '/tmp/9b4d56c6bf75dc6718768cda6940025a20150806-3-14gq1uq.mp4'
2015-08-06T15:38:40.025037+00:00 app[web.1]: [AV] Running command: if command -v ffmpeg 2>/dev/null; then echo "true"; else echo "false"; fi
2015-08-06T15:38:40.028329+00:00 app[web.1]: 
2015-08-06T15:38:40.028332+00:00 app[web.1]: Av::UnableToDetect (Unable to detect any supported library):
2015-08-06T15:38:40.028333+00:00 app[web.1]:   app/controllers/works_controller.rb:18:in `create'
2015-08-06T15:38:40.028335+00:00 app[web.1]: 
2015-08-06T15:38:40.028336+00:00 app[web.1]: 
2015-08-06T15:38:40.028629+00:00 app[web.1]: source=rack-timeout id=dd06eb06-cad5-4236-8788-e5f59f7fe631 wait=7850ms timeout=15000ms service=332ms state=completed
2015-08-06T15:38:40.023226+00:00 app[web.1]: [AV] Running command: if command -v avprobe 2>/dev/null; then echo "true"; else echo "false"; fi
2015-08-06T15:38:40.027118+00:00 app[web.1]: Completed 500 Internal Server Error in 292ms

models/work.rb

has_attached_file :video,
    :styles => {
        :mp4 => {
            :geometry => "640x480",
            :format => 'mp4',
        },
        :thumb => {
            :geometry => '300x300',
            :format => 'jpg',
            :time => 10
        }
    },
    :processors => [:transcoder]

Gemfile

gem 'aws-sdk', '< 2.0'
gem 'paperclip', '~> 4.2'
gem 'paperclip-ffmpeg', '~> 1.0.0'
gem 'paperclip-av-transcoder'
gem 'delayed_paperclip'
gem 'rmagick', '~> 2.13.4'

config/environments/production.rb

config.paperclip_defaults = {
   :storage => :s3,
   :s3_credentials => {
     :bucket => ENV['S3_BUCKET_NAME'],
     :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
     :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
   }
}

Any help would be incredible

Check this out Heroku ffmpeg buildpacks for video uploads

There are some things you need to have setup in heroku

touch .buildpacks
touch Procfile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM