I'm migrating from Active Record to Mongoid, and this paperclip stuff used to work fine. I'm using Ubuntu 12.04.
I've got this code in my mongoid document:
has_mongoid_attached_file :photo,
:styles => {
:thumb => "60x60",
:small => "100x100",
:medium => "300x200",
:large => "600x400"
},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "#{Rails.env}/merc:attachment/:id/:style.:extension",
:url => ":s3_alias_url",
:bucket => '%^&*&^'
I have the rmagick gem installed and the command_path pointing to where the various imagemagick commands are -> '/usr/bin'.
I'm using Unicorn as my webserver, and I have verified that identiy and convert are available by putting this in my view:
<%= `which convert` %>
<%= `echo $PATH` %>
But alas, when I try to upload the image I get :
Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is not recognized by the
'identify' command. Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is not
recognized by the 'identify' command. Photo
/tmp/qdoba20121005-27609-1m3kq9c.jpg is not recognized by the
'identify' command. Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is
not recognized by the 'identify' command.
Seemingly one for every one of the styles I have defined.
I've confirmed that the file exists, and I can run identify on the file from the commandline.
Any help will be appreciated. Thanks!
There is a recent update to the Cocaine gem that is breaking the imagemagick filenames for a lot of people - check it out because rolling back Cocaine to the previous version may help.
See here:
https://github.com/thoughtbot/paperclip/issues/1038
Related
I am able to upload videos locally. The videos are processed using paperclip and all the meta data is saved correctly, as well. When I tried to upload a video using our remote server, I received the error:
Av::UnableToDetect (Unable to detect any supported library)
I have installed ffmpeg using LinuxBrew. It says everything is installed correctly (checking which brew and which ffmpeg, as well as checking if the gem is appropriately installed).
When I have styling in my model for the video (which is what enables the meta information to be stored and to have control over how the video is uploaded) it doesn't work remotely.
has_attached_file :video, path: "/posts/:id/:style.:extension",
:styles => {
:medium => { :geometry => "493x877", :format => 'flv' },
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 },
# :mobile => {:geometry => "640X480", :format => 'mp4', :streaming => true}
}, :processors => [:transcoder]
However, when I remove this from my model and have:
has_attached_file :video, path: "/posts/:id/:style.:extension"
The video is uploaded to S3 (without the data or styling that I need).
Any help would be greatly appreciated. I think AV is having trouble finding ffmpeg but I am not sure why or how to go about fixing it. Thanks in advance for any advice.
I had the same issue just this past week - Try this!
Video model:
has_attached_file :video, styles: {
:medium => {
:geometry => "640x480",
:format => 'mp4'
},
:thumb => { :geometry => "160x120", :format => 'jpeg', :time => 10}
}, :processors => [:transcoder]
validates_attachment_content_type :video, content_type: /\Avideo\/.*\Z/
Make sure you already bundled:
gem 'paperclip', '~> 4.3.1'
gem 'aws-sdk', '< 2.0'
gem 'paperclip-av-transcoder'
gem "paperclip-ffmpeg", "~> 1.2.0"
Run the paperclip migration:
rails g paperclip model video
Be sure to add in post_controller.rb:
private
def bscenes_params
params.require(:post).permit(:video)
end
Upload form:
<%= f.file_field :video %>
Show page:
<%= video_tag bscene.video.url(:medium), controls: true, style: "max-width: 100%;" %>
At this point you should get this error:
Av::UnableToDetect (Unable to detect any supported library):
For Mac
Go to your terminal and type in:
brew options ffmpeg
Then run the following to install ffmpeg:
For older versions of brew recipe:
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libas
For newer versions of brew recipe:
brew install ffmpeg --with-fdk-aac --with-sdl2 --with-freetype --with-frei0r --with-libass
For Linux Mint / Ubuntu / Debian based Linux
Open a terminal (Ctrl + Alt + T) and execute following commands one by one to install ffmpeg.
sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install ffmpeg
At this point Video uploads will work locally
Now for remote uploads you will need to setup https://devcenter.heroku.com/articles/buildpacks
This should now bring you to your error
Av::UnableToDetect (Unable to detect any supported library)
You will need to create a Procfile in the root of your app directory more information about Procfile here: https://devcenter.heroku.com/articles/procfile
touch Procfile
Hope this helps!
Update:
So this is definitely related to the :hash_data option, specifically the :updated_at segment. Somehow the files are being saved to the S3 bucket with a different :updated_at value than Paperclip uses to read the file. Could this be due to some race condition, considering that it occurs intermittently? As I mentioned below, this issue began after upgrading Paperclip to 4.2.1.
I will greatly appreciate any thoughts/tips you guys have on this. Thank you!
When uploading images via Paperclip to S3 bucket, it sometimes saves the files with a different filename than that returned by the attachment#url method. For example, an image is saved to
main_event_photos_46_47fd4f3c2fea17fbb7a0bd27c648911557f9e12b_main.png
However calling #event.main_event_photo.url(:main) returns
main_event_photos_46_15744de74a36207b672356b5ad4c6b30eb4ba85f_main.png
So as you can see, the :hash section of the interpolation does not match, and I have no way of finding the actual url besides opening the bucket in the S3 console. This issue seems to occur about half the time. Sometimes uploading the exact same file does save properly, and the url method accesses it correctly.
This issue began occurring after we upgraded Rails/Ruby/Paperclip. We're now using:
Ruby 2.1.5
Rails 4.2.0
Paperclip 4.2.1
Note that on development, files always save correctly (local filesystem). I have scoured Stackoverflow and Google to no avail. Please let me know if I can provide any additional information. Thank you!
EDIT:
Model:
has_attached_file :main_event_photo, {
:styles => { :original => {:geometry => "1280x800#", :format => 'png'},
:main => {:geometry => "640x400#", :format => 'png'},
:thumb => {:geometry => "330x220#", :format => 'png'}
},
:convert_options => {:original => '-quality 80',
:main => '-quality 80',
:thumb => '-quality 80'
},
:default_style => :main
}.merge!(PAPERCLIP_STORAGE_OPTIONS) # this is defined in the config/environments
validates_attachment_content_type :main_event_photo, :content_type => ['image/jpeg', 'image/png', 'image/gif', 'image/x-png', 'image/pjpeg']
validates_attachment_presence :main_event_photo
Form (basically):
<%= simple_form_for(#event, :url => { :action => #event.id.nil? ? "create" : "update" }) do |f| %>
<%= f.file_field :main_event_photo %>
<% end %>
Note we have many models with Paperclip attachments, and the issue occurs on each.
So this turned out to be the result of a bug. I upgraded Rails to 4.2.1.rc1 which was released last week, and the issue was resolved. If anyone wants more information, check out the thread on Github: https://github.com/thoughtbot/paperclip/issues/1772. It includes a workaround for those who can't upgrade Rails.
I got this error in airbrake at production: (I just uploaded a version with an upgrade of both rails and ruby, to 1.9.3 and 3.2)
Cocaine::ExitStatusError: Command 'convert /tmp/photo (1)20130424-3742-dohg6e.JPG -auto-orient /tmp/20130424-3742-eiksvr' returned 2. Expected 0 Here is the command output:
my paperclip code:
has_attached_file :photo,
:styles => {:original => "1024x1024>", :large => '800x600>', :thumb => '120x72#'},
:convert_options => {:original => '-strip -quality 90', :large => '-strip -quality 90', :thumb => '-strip'},
:processors => [:auto_orient, :thumbnail],
:url => "/system/statuses/:id_partition/:style.:extension",
:path => ":rails_root/public/system/:id_partition/:style.:extension"
what does this error mean? and how can i handle it?
thanks
I'm no entirely sure. But it seems that your production server doesn't have the ImageMagick library installed properly.
cocaine is a library for executing commnad tools.. I believe that it is trying to call some imagemagick command and returning somekind of error
Paperclip rescue's any Cocaine error, including things like Segmentation Faults in ImageMagick. It returns a '' i.e. an empty string. Line 27 of geometry dector factory.
I'm using the paperclip gem (3.0.4) which suddenly stopped working as it is no longer creating the thumb folder, only original. Because of this my code can't find the image that was uploaded and errors out.
In my model I have:
has_attached_file :image,
:whiny => false,
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:url => "/system/:attachment/:id/:style/:filename",
:styles => { :thumb => "150x100#" }
This code hasn't changed, and when I attempt to render my view I get the following error:
/public/system/images/52/thumb/2011-03-16_07-49-52_412.jpg not found
Looking in my file system I have, /public/system/images/52/original/2011-03-16_07-49-52_412.jpg
Could this be an issue with ImageMagick?
Any idea what is causing this and how to resolve it to ensure the thumb folder is being created? Thanks for your time and assistance.
I installed the paperclip plugin and was able to use it locally. When I configured it to work with amazon S3 I keep getting the NoSuchBucket (The specified bucket does not exist) error. Paperclip documentation states that the bucket will be created if it doesn't exist but clearly
something is going wrong in my case.
I first insalled aws-s3 gem (v0.6.2)
then also installed right_aws gem (v1.9.0)
both have corresponding
config.gem "aws-s3", :lib => "aws/s3"
config.gem 'right_aws', :version => '1.9.0'
lines in environment.rb file
The code for the image.rb file with paperclip is as follows:
class Image < ActiveRecord::Base
belongs_to :work
has_attached_file :photo, :styles => {:big => "612x1224>", :small => "180X360>", :thumb => "36x36#"},
:storage => 's3',
:s3_credentials => YAML.load_file("#{RAILS_ROOT}/config/s3.yml")[RAILS_ENV],
:path => ":attachment/:id/:style/:basename.:extension",
:bucket => 'my-unique-image-bucket'
attr_protected :photo_file_name, :photo_content_type, :photo_size
validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 3.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png', 'image/gif']
end
I'm not entirely sure this is it, but your loading of the s3_credentials is different than what I'm using on my production sites.
My config line is:
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml"
Instead of
:s3_credentials => YAML.load_file("#{RAILS_ROOT}/config/s3.yml")[RAILS_ENV]
it should create but the bucket but this was a bug at one point :
http://groups.google.com/group/paperclip-plugin/browse_thread/thread/42f148cee71a0477
i recently had this problem and it turned out to be the servers time was hugely off and s3 wouldnt allow any updates "that far in the future" or similar but the rails error was NoSuchBucket...confusing
..
I have installed the s3fox plugin for firefox and created the bucket with the plugin. Now Paperclip works fine with S3 as the bucket identified is already created.
But I am still curious about paperclip's inability to create new buckets with the code above.
In case anyone winds up here via google: I saw this same error when I mistakenly switched the order of the 2nd and 3rd parameters I was passing to AWS::S3::S3Object.store.
It's not your case, but AWS doesn't allow upper case letters in bucket name and paperclip doesn't check that, failing in create_bucket.