#134 Paperclip
Need to add image attachments to a model? See how with paperclip in this episode.
- Download:
- source codeProject Files in Zip (150 KB)
- mp4Full Size H.264 Video (11.5 MB)
- m4vSmaller H.264 Video (7.81 MB)
- webmFull Size VP8 Video (20.3 MB)
- ogvFull Size Theora Video (15.3 MB)
Thanks Ryan for that railscast! A few weeks ago I was build a function like this in my app with attachment_fu and ImageScience. Are there any drawbacks in relation to your solution?
Hi Ryan! One question! Is it possible to make Paperclip work if I need my model to have many attachments? If it's not possible, maybe you know some other plugins?
@Alex
Have a look at this tutorial: http://www.practicalecommerce.com/blogs/post/432-Multiple-Attachments-in-Rails
It's for attachment_fu but it's the same concept for paperclip.
Also there is a polymorphic paperclip plugin, see this tutorial
http://burm.net/2008/10/17/ruby-on-rails-polymorphic-paperclip-plugin-tutorial/
As far as I know there is a polymorphic paperclip plugin. Maybe that's what you are looking for, Alex.
I liked paperclip plugin, but I need to sort out what to do with many attachments.
I really really want to stress that uploading files is _easy_!
http://gist.github.com/20698
That gist is just a file upload, though. No file size and/or mime type validations there. Or imagemagick fanciness.
@PanosJee - You can change the file type validations if you want to upload pdfs or docs. Paperclip can handle pretty much anything you want to upload
@Aditya Sanghi - If you want to attach multiple uploads to a model just create an assets model using paperclip and use a has_many relationship
We use paperclip on a current project and it works good except for:
1. When you delete an attachment it does not delete the directory it created for the file. Thus over time you are left with hundreds of empty directories on your server.
2. Take an Outlook email and drag it to your desktop, it'll create a .msg file. Now try to upload that file using a webkit based engine (Chrome, Safari) and Paperclip will crash. No problem with FF or IE.
I've tried to get a solution from Paperclip Google group but the developers have been unresponsive to the second problem and don't think the first problem is a problem.
Is this a good solution to use if you have a model that needs to 'has_many' photos? its not clear how you would adapt this to the situation where you need to have a variable number of photos associated with a model.
Thanks for any insight on this.
Hey Ryan
Another good one and again we seem strangely in sync with your railscasts - Rob posted about Paperclip on our blog yesterday - including instructions to help long suffering (in general!) windows users out:
http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip
Chris
@zachary: there's a plugin on github for polymorphic paperclips. or you can setup polymorphism manually (which is what i did) as i didn't want an additional table in the middle.
Great screencast, Ryan! A small note to add. To refresh the thumbnails after a change in the attachment models, there is no need to upload the images again. You can simply run this --
rake paperclip:refresh
For those wondering how to handle the case where you want many photos per product. All you need to do is create a second model (ProductPhoto) with a one-to-many association to product. Use paperclip on ProductPhoto and there you go. Now a product can have many photos.
@leethal, thanks! It's nice to see file uploads on their own is fairly simple.
@Chess, it's an open source project, so if the developers aren't willing/able to fix these problems you can always fork it on GitHub and fix them. Maybe someone already has as there are a number of forks already.
@Nilesh, cool, didn't know about that Rake task. Thanks! That's one thing, I think Paperclip could use more complete documentation.
This is very cool.
@Jim Neath - sounds like paperclip can handle any file type, great!
Is it possible to store the attachments in the DB? I'd like to store attachments in the database for things like drivers licenses, social security cards, etc.
using windows i always find myself with C:/InstantRails-2.0-win/ruby/bin/mongrel_rails: No such file or directory - iden
tify "C:/DOCUME~1/Owner/LOCALS~1/Temp/stream.2748.0"
and not being able to covnert to styles small even with imagemagick and rmagick installed in the log file i just saw
Rendering C:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/templates/rescues/layout.erb (not_found)
any idea how can i fix it (switching for linux aint an option right now)
thanks in advance
@Ben,
I used this as a basis for storing some simple pictures in my database:
http://dizzy.co.uk/ruby_on_rails/contents/store-file-uploads-in-database
I wasn't trying to do exactly the same thing as the author, but it wasn't too hard to adapt. Having said that, I'm not sure it is better than the way Paperclip or Attachment_fu does it by default. I can see pros and cons both ways.
@AdrianoD: I switched completely to cygwin and use ruby (on rails) inside there. I think I have less problems with plugins etc. Maybe you should try also.
Here are all the links I needed to set it up: http://delicious.com/lenart/cygwin
Did anyone test if an attacker can concatenate code to the image and have it execute when the image displays?
I almost cried watching this! :) Do you have any idea how long it took me to get attachment_fu working and cropping and ImageScience and RMagick and memory leaks and ImageMagick etc and then you did it in 5 minutes arg!!!!!
Great stuff, thanks Ryan.
@AdrianoD
I struggled with the same problem but running under passenger. The solution for me was to add the following file to the initializers:-
# config/initializers/paperclip.rb
Paperclip.options[:image_magick_path] = "/usr/local/bin"
Restart the server and voila! (at least for me YMMV!)
Ryan, I love your screencast again. Thanks for all your nice work!
I have one question. I try to save photos on a one to many relationship. It works well only i want to change the path. I want to have a parent_id in the url and the path.
ive got a room and a room has many pictures
This isnt working:
:path => ":rails_root/public/assets/room_photos/#{self.room.id}/:id/:style/:basename.:extension"
:parent_id or :room_id isnt working as well.
Somebody has an idea?
@AdrianoD, Windows is mentioned at the beginning of this article, so that might help.
http://tinyurl.com/5nrl3k
@Thomas, that's an interesting question and I haven't looked into it. I don't think any code would be executed on the server side, but maybe when the client renders it? However, if so then I think this would be a security flaw with the image codec itself and not necessarily with our Rails app.
@Michael, yes that's possible by making a custom interpolation. It's mentioned near the end of this article.
http://tinyurl.com/5nrl3k
@Andrew, if you're using attachment_fu with good success then I wouldn't bother switching. But for new projects I recommend paperclip for these reasons:
- a separate attachment model isn't necessary.
- image library isn't required (unless you need to resize)
- smaller memory footprint
Those are just some things I've heard, but honestly haven't done much research.
@Ryan, for those of us that choose to switch from attachment_fu to paperclip, is there any way to continue to use the separate attachment model?
@James, yep. I'm not sure of all the steps involved. But you can keep your attachment model and just apply paperclip to that.
there is an other very smart plugin for fileuploads called uploadcolumn. i use it on several projects and at first sight it is exact the same thing as paperclip ..
http://uploadcolumn.rubyforge.org/
Thanks Ryan! I love paperclip. I have a suggestion for a future episode...charting/graphing!
I am using Paperclip to upload photographs, and wanted to have the DateTime the photo was taken extracted from the uploaded file's EXIF metadata, and saved as an attribute on my Picture model.
After some hopeless attempts using before_save and after_save callbacks, I ended up just overwriting Paperclip's photo= method: http://pastie.org/310107
And what about width="" height=""?
It would be great to save width and height of resized image in its file name...
Is there a way to upload an image by typing the url of the image location, instead of using the file_field. Ive been looking for a good tutorial for this and cant seem to find any. Thanks
@Steve, take a look at http://almosteffortless.com/2008/10/24/easy-upload-via-url-with-attachment_fu/
That's how you do it with attachment_fu, though – dunno if you can do the same trick using Paperclip.
Great episode! I set up Paperclip on my local machine (Leopard, running Passenger) and after commenting out the "rescue" in Paperclip::Attachment#post_process, I get this crappy "/tmp/stream.3916.0 is not recognized by the 'identify' command" error.
I have my ImageMagick path set correctly and proper permissions. What gives?
Sorry for asking, but when I run script/plugin install git://github.com/thoughtbot/paperclip.git on windows I only get information: removing: D:/testy/vendor/plugins/paperclip/.git
What should I do to install plugin from git on windows?
when i use git to install paperclip via "script/plugin install git://github.com/thoughtbot/paperclip.git", i get the following error (after which, if i try to use the paperclip generator, it says it doesn't exist)...
http://pastie.org/318325
If you could give me ANY help i would appreciate it. i can't tell if my git install is screwed up, or if i'm missing something. everyone else seems to have an easy time installing this.
Hi Yves, Laser Demon, all,
I got it working with an intializer: http://gist.github.com/26476 - Passenger + Paperclip that is.
via http://www.fuzzylizard.com/archives/2008/07/05/954/
Hey Bryan, as a rails newbi from Germany I love your casts. And with regards to paperclip: my project uses file_column but I would like to switch to paperclip. Do you know how I can make the switch smooth so that I cann still use the so far uploaded Files (path: system/user/picture/<id>/<filename>)? Great if you could help me.
All the best. Im a big fan.
Nick
@Laser Lemon
I am getting the same error on two different machines, a vista and an XP.
I do not have imagemagick installed.
AppData/Local/Temp/stream.2620.0 is not recognized by the 'identify' command.
Solved my issue by installing ImageMagick-6.4.5-8-Q16-windows-dll.exe
Any recommendations against using fleximage? http://github.com/Squeegy/fleximage/wikis
paperclip looks very easy, but so does fleximage. The one thing that really catches my attention about it is the dynamic resizing:
http://github.com/Squeegy/fleximage/wikis/rendering
From what I understand it will render whatever size you want at anytime after the upload, so you don't have to figure out all your sizes in advance and then build your own rake task if you want to make a new size.
Hi @all,
do anyone of you know how to include by paperclip generated thumbnails to the to_xml methode?
If I use methods I can specify an array with fields but there I can't say the variation (e.g. small part of photo).
Any ideas?
Thanks for your help,
Steffen
For some reason when I used Paperclip to resize images for thumbnails it produced files of 0bytes. I had to specify in the model that I wanted jpg files created even if the original was a jpg.
In the following instance the 'small' picture would be fine, but the 'regular' size would be corrupt.
has_attached_file :photo, :styles => { :small => ["100x100#", :jpg], :regular => "300>"}
I'm using paper clip to upload documents (doc and rtf) it workd fine for a while then it stops suddenly! I can't figure out what's the problem but when I restart my mongrel instance it works fine again... anyone knows anything about it??
Checked my mongrel log and found this: Error reading HTTP body: #<RuntimeError: Socket read returned insufficient data: 10379>
Hi,
thanks Koen Van der Auwera.
Another way for solving this is setting PATH as environment variable for Mac OS X 10.5 in /System/Library/LaunchDaemons/org.apache.httpd.plist:
http://gist.github.com/28112
One more thing… I haven't seen a Fileupload plugin which is capable of keeping the temporar file of an upload if the validation fails.
For instance we've the model Medium which has_attachment :file and validates_presence_of :comment. If we left out the comment but specified a :file (let's say a big one... 200MB...) the validation will fail and the data is lost.
It's pretty annoying if you have to upload the file again.
As a workaround you can reflect the validation on client side... but it's not a solution for the problem.
Yves i'm nearly sure I've done that in the past with attachment_fu. I wanted to use the mp3-info library to extract data from a sound file upload even if the upload failed in validations.
You can use a before_save method in the model to access the file (using self.temp_path) before it has been saved. You can then do anything you want with it.
Or you could write your own validations, or modify the existing ones.
For anyone on OSX getting the ".../tmp/stream.3916.0 is not recognized by the 'identify' command" error, it's probably that identify is not in your path. The macport install and other installs do not always seem to get this right.
To fix:
* check if "identify" is in your path from the same terminal where you're about to run your "ruby server/script" command - just try to run it from the terminal prompt
* if it won't run, try entering these commands:
tom:~ tom$ export MAGICK_HOME="/opt/local/"
tom:~ tom$ export PATH="$MAGICK_HOME/bin:$PATH"
tom:~ tom$ export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib"
(you may have to adjust MAGICK_HOME to match your install)
After that, try running identify again from your RoR site's root dir. It should now work. If it does, run your server and see if your photos now work.
(You'll want to make sure the above PATH changes are made permanent if this fix does help.)
Hello Ryan,
Do you know if it's possible to create an attachment inside a controller?
I mean, I have some text stored in a string. I want to create an attachment that is a plain text file containing the contents of that string into a given model object.
Is this possible?
Thanks!
default_url and default_style are also useful options.
See paperclip.rb in the code for explainations.
Like a bunch of other people on here, I'm setting up a model with multiple attachments.
I've followed this Railscast and Ryan's article on multiple models in one form in Advanced Rails Recipes (#13).
Here's the code I have so far:
http://gist.github.com/33011
As you can see I'm receiving an 'unknown attribute' error. I think this has to do with the way I'm using a new attribute writer method for in the model, and I don't think paperclip has run at that point. So, there is no attachment attribute yet, and thus the error.
Any advice is appreciated.
P.S. I've looked at the other articles mentioned above on polymorphic associations with paperclip, but none of them worked for me.
I was having a heck of a time getting Paperclip to generate thumnails, even though I have working copies of ImageMagick and RMagick installed. My IM was built from source and installed to /usr/local/bin. The solution was to add a line to my development.rb:
Paperclip.options[:image_magick_path] = '/usr/local/bin/'
Hope that helps someone else out!
For anyone who's interested I've updated a gist with a working example of multiple file attachments using Paperclip.
http://gist.github.com/33011
Notes about the gist:
1. Page has many Assets
2. Asset has Paperclip attachment
3. Paperclip attachment is called 'file'
no one has any info about: Error reading HTTP body: #<RuntimeError: Socket read returned insufficient data: 10379>??
@Chess, in regards to deleting the folders, when I use 'has_many :photos, :dependent => :destroy' in my model that deletes the photos as well as the folders that contain them.
Thanks for the great post!
I just have a question...I need to upload excel sheets and delete them once i save the data in them onto the database.
I am stuck at the deletion part of it.
I am trying to use Paperclip with a form_remote_for (ajax form) .. but it seems to not recognize the associated form field as being related to the paperclip generated fields.
i.e. I am using <%= form.file_field :pdf %>
and when I submit, I get a message indicating the Pdf must be set - as if it isn't being sent. I can verify it is in the params in the log and that the form is using multipart=>true
Are there known issues or extra steps I must take to get Paperclip to work with a remote form (ajax)?
Thanks - great railscast and plugin!
@Chess: deleting the object destroys the attachment as well as the folder structure. Only the public/<modelname> remains.
The id/style/style.extn gets deleted.
Hi Ryan,
I'm pretty new to Rails at this point, and your screencasts have been an amazing resource, so first and foremost - Thank you!
I was able to get image uploads working, but my question is this: at some point in the life of my application, what is going to happen if (obviously a big "if," but it's what I'm hoping for) I am hosting enough files that I reach the 32,000 sub-directory limit? Is there a simple solution to this problem (if it is in fact a problem)?
Thanks so much!
Hi Ryan,
I found that if you edit a product that have an image, if you save it without upload a new one, the first image is lost. Is this a bug of paperclip?
Thanks!
In response to Alex... A good tip, if you have not already thought of this or ruled it out for your specific needs, is to come up with a unique file naming convention to reduce the amount folders needed for categorization. I did some part time work with an image host and they used date-stamping in the file name along with a few other key words to avoid requiring folders. I believe they were hosting around 25k files, so this might still be small scale in comparison if what you may need.
I found a really cool method for automatically unsharpening generated thumbnails when uploading them through Paperclip. If you've ever been bothered about the fuzziness in your generated thumbnails, you should check this out:
http://natemiller.org/2009/2/28/automatically-unsharpening-thumbnails-with-rails-and-paperclip
@John, I've had the same problem as you, i.e. trying to make paperclip work with RJS & AJAX, and getting the "photo must be set" error.. Apparently, It's got something to do with AJAX not being able to read the local file system... I will continue to investigate, and would really appreciate if anyone else with a solution could post it here...
Cheers
Is there any prospect of paperclip integrating an upload progress meter?
Hi . . i m facing a problem. when i write has_attached_file in my model .. i get an error on running the server that undefined method has_attached_file ,,, please help me solving this problem. i need it urgently... please.. i m using windows , netbeans and have installed paperclip as a gem because it is not available as a plugin,,
Somewhere read that :command_path should be used instead of :image_magick_path when setting path of imagemagick, as the later will be deprecated. And when using macport's ImageMagick, /opt/local/bin must be used as the value. Something like this:
Paperclip.options[:command_path] = "/opt/local/bin"
If you're using Windows and you're getting the "not recognized by the 'identify' command." error, here's a solution: http://blog.jonathanhinson.com/2009/04/27/getting-paperclip-working-in-windows/
General tip: For the plugin installation command to work in the command line, be sure you've got git installed. Otherwise, the command fails silently.
I got stuck on this for ages.
There seems to be a bug where the validations ignore :if or :unless parameters.
Here is the reported bug and a patch.
https://thoughtbot.lighthouseapp.com/projects/8794/tickets/131-validates_attachment_presence-should_validate_attachment_presence-should-take-if-and-unless-options#ticket-131-1
I downloaded the episode's code from Ryan's Github account however as soon as I initialize the server and go to localhost:3000 I get this error:
"uninitialized constant ApplicationController"
The Application.rb is where it's supposed to be and has the content as written by Ryan. Any ideas as to what's going on? Any help is welcomed. Thanks everyone.
@AcaKaliman
application.rb has since been renamed application_controller.rb. Rename this file and try it again. It was successful for me.
@Steffen
I wrote a blog post about paperclip and to_xml here:
http://www.mrkris.com/2009/06/18/paperclip-resized-image-details-in-to_xml/
If you need multiple photos for your object, I recommend this well written tutorial:
http://www.webyfi.com/?p=11
Read the comments as well, there are a few hints that might help you thru.
To those wanting "ajaxy" file uploads, look into the iframe remoting pattern. There are some articles on iframe remoting and attachment_fu that will work just as well for paperclip.
Hey,
I installed paperclip, but cannot create a migration for it. I try this:
script/generate paperclip user avatar
And get a long string of errors, starting with this:
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:376:in `new_constants_in': You have a nil object when you didn't expect it! (NoMethodError)
You might have expected an instance of Array.
The error occurred while evaluating nil.empty?
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:202:in `load_file'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:94:in `require_or_load'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:248:in `load_missing_constant'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in `const_missing'
from /projects/Vitae/vendor/plugins/paperclip.git/lib/paperclip.rb:113:in `included'
Any ideas? I can't find anyone else who's had this problem.
Hi...I am getting the following error while trying to upload a jpg file using paperclip.
identify: no decode delegate for this image format `I:/temp/stream.2652.2' @ constitute.c/ReadImage/503.
Can somebody help me with this?
Hello Ryan,
While uploading a file, I also need to scan whether the uploaded file is a virus or not. Can you please tell me how to do it?
Thanks,
Madan Kumar Rajan
Crikey - could it be any harder to install ImageMagick on OS X?! I downloaded the binary release and got it working easily, but I can't get the rmagick gem to see it at all. Frustrating!
Thanks for the great scrn cast Ryan!
Is there any attachments content type white list? Users should not be able to upload malicious files like .exe
Hi guys,
I'm a newbie.
I get the following error when I reload the form after installing paperclip:
NoMethodError (undefined method `has_attached_file' for #<Class:0xb7ae3140>):
app/models/product.rb:4
app/controllers/products_controller.rb:3:in `index'
Please help.
I have the problem that we use 'attachment_fu' in one of our projects. There is a class named 'Attachment' and this is associated to different models. e.g. StaticPage has_many attachments.
Now I want to add paperclip too and run into a name-conflict.
StaticPage.attachments...... doesn't work since paperclip is installed and brings up errors like:
undefined method `quoted_table_name' for Paperclip::Attachment:Class
StaticPage doesn't use paperclip at all and it's just the presence of Paperclip causes this errors.
I wonder if there is a way to 'rename'/'refactoring' the used 'Attachment-Model' to something like 'BinaryAttachment' throughout the entire project. of course RexEx through the project would be work - but I'm not a RegEx-specialist and therefore I'm looking for a more simpler way to do this.
Does anyone know about a refactoring tool like XCode has to rename Classes? Or how would you solve this?
@Andi
I ran into the same namespace issue with my own attachments join table. I just set-up my asset association like this and it seems to work fine:
has_many :attachments, :class_name => '::Attachment', :as => :from, :dependent => :destroy
The key here being the class name.
Hi, for those who have still problem with paperclip on windows and are still getting error:
"not recognized by the 'identify' command." and the solution: http://blog.jonathanhinson.com/2009/04/27/getting-paperclip-working-in-windows/ does not work:
I've reinstalled ruby with "http://rubyforge.org/frs/download.php/66871/rubyinstaller-1.8.6-p383-rc1.exe", uninstall imagemagick and install imagemagick 6.5.8-6 q16 and nothing more and it works! No more errors.
Hope it helps..
H.
Hello,
I get this error message every time i try upload am image.
NB: Foto is BD column name.
There were problems with the following fields:
* Foto /tmp/stream20091228-2242-xptimu-0 is not recognized by the 'identify' command.
* Foto /tmp/stream20091228-2242-xptimu-0 is not recognized by the 'identify' command.
Can you help me? thanks in advance
@Narcisse
I am having the save problem, have tried everything i know, but no luck
please help us!
If you run into "is not recognized by the 'identify' command"
delete imagemagick and reinstall via macports
sudo port install ImageMagick
Anyone have experience with conditional validations in paperclip?
In my case, an image is optional, but if it's present, I want to validate its size and format.
Any ideas or code?
@graham:
For 'validates_attachment_content_type', you can add :allow_nil => true. For 'validates_attachment_size', you can use :allow_nil => true after a quick fix as follows:
Open your paperclip.rb plugin file.
Find 'def validates_attachment_size name' string.
Replace 'validates_inclusion_of' rows with the following:
validates_inclusion_of :"#{name}_file_size", options.merge(:in => range, :message => message)
Save it. Restart your server. Try again. Let me know if this works. Good luck.
When uploading an image, the exif data stored on the file may produce unintended results. IE... digital cameras store the rotation/orientation of images in the file. Mac OS reads this data, and automatically rotates the image locally (and the image appears to be oriented correctly). However, after uploading, imagemagick ignores the rotation/orientation information in the photo, causing an undesired 90 degree rotation. Keep in mind, that this only happens on unprocessed images. Anywho.... I was tearing my hair out on this, and saving a copy of the image in photoshop seemed to fix the problem.
Nice vid! Thank you!!
did anyone figure out how to use paperclip to attach files in ajax forms (form_remote_tag/form_remote_for)? this seems like a big limitation to me.
what are the workarounds?
great tutorial ryan!
thanks
vinod have a look there http://khamsouk.souvanlasy.com/articles/ajax_file_uploads_in_rails_using_attachment_fu_and_responds_to_parent
I have a question too, is there a way with paperclip to convert png and gif files' alpha channel to a white background?
John, You cannot upload files via Ajax, Use an hidden iframe instead. Or just leave the idea of Remote form with file upload.
Good luck.
I am getting the same "is not recognized by the 'identify' command" error. I have found that if I take away the :styles of has_attached_file, I can successfully post the image. I would obviously like to be able to resize the image, though. Can anyone help?
Sorry, forgot my email address on last post...
I am getting the same "is not recognized by the 'identify' command" error. I have found that if I take away the :styles of has_attached_file, I can successfully post the image. I would obviously like to be able to resize the image, though. Can anyone help?
@Laser Lemon
same problem, solution was just to type this in linux console:
sudo ldconfig
... oh and dot forget to add
Paperclip.options[:command_path] = "/usr/local/bin"
to config/environments/development.rb
Just to mention for all the windows users out there: I'm using cygwin (v1.7.1.1) with imagemagick and paperclip works fine. No need to install imagemagick as an extra package. Main development is on a Mac though but cygwin is a good way to work cross-platform.
@Ryan: Thanks for your great screencasts!
I am getting:
Couldn't find 'paperclip' generator
What does this mean? Any help would be appreciated and a big thankyou to Ryan! Your screencasts are invaluable.
The paperclip works on ubuntu but on windows it gives an some error.
the error is
" There were problems with the following fields:
Avatar C:/DOCUME~1/ozone/LOCALS~1/Temp/Water lilies,2700,0.jpg is not
recognized by the 'identify' command.
Avatar C:/DOCUME~1/ozone/LOCALS~1/Temp/Water lilies,2700,0.jpg is not
recognized by the 'identify' command "
any idea ??
i'm almost stuck here
thanks
Hi guys and girls :)
I use paperclip and it is wonderful plugin/gem however when I upload the picture I want to have only the styled versions of it :style=>{...} and not to upload the original. Paperclip seems always to upload the original image as well and I don't want to have that.
Any ideas?
Cheers
I found it at last.
If a style is called :original, it leaves only that one.
Cheers
J.
Can anyone point me in the direction of using Paperclip for file attachments that are not images? I can attach, but get errors when trying to retrieve the files. I'm pretty sure it's due to the :url path I have in my model, but I'd like a tutorial for non-image attachments so I can follow from scratch... thanks in advance.
After hours of "not recognized by the 'identify' command" I can recommend any windows-user to install imagemagick into a path w/o whitespaces. still you'll need to set the command_path like:
Paperclip.options[:command_path] = "C:/ImageMagick-6.6.2-Q16/"
(ve put it into the development.rb). good luck ;-)
How do you add an image with fixed dimensions as well as create a thumbnail? so you can click on the thumbnail and view the bigger image
Is there any easy way to validate the file type or file size ONLY if the form is being submitted with an attachment?
Hi Ryan, I am using rails 3 and trying to use paper clip cropper but it is giving below error;
NameError (uninitialized constant Paperclip::Cropper)
I tried to do this with the help of http://asciicasts.com/episodes/182-cropping-images
@ lunas I had the same error. I was using rails3 beta4, and I'm sure I created the correct Cropper class under the lib folder, but still got error. I think it might me some bugs that the Cropper class just can't be auto-loaded. So require it explicitly may solve the problem, though it's not a permanent way but still worth it because you can move on.
This is my way how I've got rid of "not recognized by..." Just adjust the validations a bit.
file_types = ['image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'image/pjpeg']
validate do |image|
image.errors.clear
image.errors.add_to_base("File missing") if image.file_file_name == nil
image.errors.add_to_base("Wrong format") unless file_types.any? { |type| type == image.file_content_type }
image.errors.add_to_base("Wrong size") if image.file_file_size != nil && image.file_file_size > 2.megabytes
end
As far as I know there is a polymorphic paperclip plugin. Maybe that's what you are looking for, Alex.
I liked paperclip plugin, but I need to sort out what to do with many attachments.
For those who is working on Windows development, you may face "identify" problem.
Please try to change
command = %Q[#{path_for_command(cmd)} #{params}]
to
command = %Q[#{path_for_command(cmd)} #{params.gsub("'",'"')}]
Hi
great post! but i have a problem, i cant view a image once its uploaded, it says "Missing" in the place of where the photo is meant to be.
what could be the problem?
I have a model with a few Paperclip attachments associated with it.
Let's say I am validating for a non-Paperclip field, but the user selects an image on their computer and submits the form.
The validation fails for the non-Paperclip field, but now the selected image is now gone.
Is there any way to save the location of the local file so that the user doesn't need to reselect the file?
Thanks,
Andy
@Andy That's exactly the problem i'm facing right now.. anyone figure out a way to fix this issue?
so i GUESS i fail to understand why reference in this tutorial aren't LAID out a little better...
example :
first line:
# models/product.rb
instead of:
# app/models/product.rb
perhaps it would be of use to more people with a little more explaining
and nowhere does it say that this tutorial requires additional files...
like where am i supposed to get these??
i guess i simply dont follow the logic of why (obvious) things are missing from the tutorial
Thanks for great work!
Paperclip was a great plugin in rails 2.*.*, but now have a problem with existing images updates. It stucks on deleting old files.
Is there any good solution for rails 3 to handle image attachments? And specially for multiple_uploads?
Excellent post, thanks.
It took me 3 hours, but I finally got delayed job working with paperclip. Hopefully this helps someone else out there:1
http://ezror.com/blog/index.shtml
http://madeofcode.com/posts/42-paperclip-s3-delayed-job-in-rails
I'm also getting a "couldn't find 'paperclip' generator" error right after I install the plugin and try to run the generator. Anyone know how to fix this?
Okay, so I just generated the migration manually, but after I edit the model and view pages, I always get "undefined method 'has_attached_file'".
Thanks, concise and helpful as always.
One quick comment regarding my experience: I could not make the file upload work using paperclip in a formtastic form; it worked fine in a standard rails form though. If anyone has a solution for making paperclip and formtastic play together nicely, I would be interested to hear about it.
Also, I would be interested to see a railscasts episode regarding file download.
Thanks,
-c
It seems Paperclip doesn't save file name on sumbit, when there are some errors raised in form. Can it be handled somehow?
Thank you
Yeah, don't forget to restart the server. Caused me anxiety at first.
:) Thanks!
If you are on Windows, the solution for the 'identity' issue its to create a paperclip.rb in the initializers folder and type:
require "paperclip"
Paperclip.options[:command_path] = 'C:\ImageMagick-6.7.0-Q16'
Paperclip.options[:swallow_stderr] = false
Obviously check for the path where you installed the ImgMagick and the version, mine its 6.7.0 and worked fine in a x64 system...
Hi I'm relatively new to rails and havvn't used a plugin before so just a little lost at the beginning.
I'm using Ruby on Rails and can't follow where does the bash code goes.
Help please
Hi I'm relatively new to rails and havvn't used a plugin before so just a little lost at the beginning.
I'm using Ruby on Rails and can't follow where does the bash code goes.
Help please
who can help me?
class Attachment < ActiveRecord::Base
has_attached_file :att,
:url => "/files/:class/:id/:style/:basename.:extension",
:path => ":rails_root/public/files/systems/:id/:style/:basename.:extension"
end
class UserLogo < Attachment
has_one :user
has_attached_file :att,
:styles => { :original => "100x100>" } ,
:url => "/files/:class/:id/:style/:basename.:extension",
:path => ":rails_root/public/files/user_logos/:id/:style/:basename.:extension"
validates_attachment_content_type :att,
:content_type => ['image/png','image/jpg','image/bmp','image/jpeg','x-png','pjpeg']
end
Hello
Is this still relevant these rails 3.X days?
Is it Gem-ified...?
TIA
Hello, I have to clone the image which I have created previously. I am just copying the data present at the image column into my cloned deal image column but this didn't displaying any image. The code is as follows:
Offer.rb
has_attached_file :image,
:styles => {
:thumb=> "100x100>",
:small => "150x150>",
:medium => "300x300>",
:large => "400x400>"
}
Offer_controller
@deal = Offer.find(params[:id])
@attr = { :nameofdeal => @deal.nameofdeal, :value => @deal.value, :image_file_name => @deal.image,:type => 'image/png'}
@offer = Offer.new(@attr)
Offers/show.html.erb
<% if @offer.image_file_name != nil %>
<%= image_tag @offer.image(:large),:class=>"offer_deal_image" %>
<% end %>
Is it possible to user paperclip to upload a pdf(no image, plz)?
and if it's possible, how can I do it?
Yes, it is possible. Just don't define any styles and you should be fine.
Is it possible to get info inside the uploaded pdf file using this gem? example I uploaded my resume and I want get my name, contact info, etc. from that pdf.
Hi,
i want to tell validates_attachment_content_type to only allow the extensions ipa, mobileprovision and plist but i am not sure what MIME-Type i have to set. I have tried ['application/.ipa'] but this is not working.
Any ideas?
Regards,
buk
which is best gem for uploading video
ActiveModel::MassAssignmentSecurity::Error in ShopsController#create
Can't mass-assign protected attributes: photo
app/controllers/shops_controller.rb:43:in `new'
app/controllers/shops_controller.rb:43:in `create'
getting an error please help me any one
Hi Ryan,
How to copy an existing images into Rails project in Rails 2.3.5.
For example I have one item it has some images, I am copying same item but here problem is how to copy existing images.Internally I am using paper clip gem for saving images.
Thanks in advance.
Thanks for the video! I'm using Rails 4.1 and still found this to be very helpful with a few tweaks. I used the Gem instead of the plugin recommendation.
This episode has been updated to Rails 5 as a blog post File Uploads using Paperclip in Rails 5