Every repository with this icon (
Every repository with this icon (
| Description: | Easy file attachment management for ActiveRecord edit |
-
3 comments Created 5 months ago by qrushbugxgs not found during tests on os-ximagemagickxReported by Kelly Felkins
My model has this declaration: has_attached_file :entity, :styles => { :small => ["400x400>", :png] }
I have a model spec that creates a model object and saves it. The attachment is a pdf file. This was failing with something like "...6192.0 is not recognized by the 'identify' command". This appears to work fine in development mode.
Apparently imagemagick relies on ghostscript when dealing with pdf files. Paperclip would issue the identify command prefixed with a command_path. Then identify would attempt a gs, but the gs command is not in the path.
My quick fix was to add the command_path to the path before issuing the identify command, like this:
export PATH=/opt/local/bin:$PATH;identify...
$ identify --version Version: ImageMagick 6.4.9-6 2009-03-08 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC $ gs --version 8.64
Comments
-
Reported by Randy Reddig
The HTML 4.01 spec permits multipart form data with an omitted filename.
Rack parses this correctly, and passes a hash describing a file using Rack::Tempfile:
{:type=>"application/octet-stream", :head=>"Content-Disposition: form-data; name="profile_image"\r\nContent-Type: application/octet-stream\r\nContent-Transfer-Encoding: binary\r\n", :tempfile=>#, :name=>"profile_image"}The original_filename method that Paperclip injects into File returns nil, which fails at attachment.rb:79:
instance_write(:file_name, uploaded_file.original_filename.strip.gsub(/[^\w\d\.\-]+/, '_'))
I suppose a reasonable fix would be to use the tempfile’s filename as a substitute for the missing filename field.
Comments
-
Reported by Dylan Markow
Using S3, it doesn't seem that copying attachments from one record to another works. The comments in attachment.rb state that "In addition to form uploads, you can also assign another Paperclip attachment: new_user.avatar = old_user.avatar", but when I try this, the second record's attachment remains empty and nothing gets uploaded to amazon's servers.
a = Post.find(1) b = Post.find(2) a.attachment_file_name # => "Attachment.pdf" b.attachment_file_name # => nil b.attachment = a.attachment b.save b.attachment_file_name # => nil
Comments
came across this too. here is a failing test:
context "photo" do setup {add_photo_to_person; @person.save} should "be reasignable" do assert @person.photo.file? other_dude = people(:turk) other_dude.photo = @person.photo other_dude.save! assert other_dude.photo.file? endend
other_dude.photo.file? fails when paperclip is configured for s3. -
Reported by thibaut Assus
In file lib/paperclip/upfile.rb Module Upfile method content_type I was wondering if it was possible to add our proper mime types (as mp3) It would be wonderful !
Comments
Comments from S. Brent Faulkner:
Not directly intended to fix this but a patch I submitted for resolution to #144 adds support for Rack::Mime (if loaded)... this commit adds many extra mime types...
http://github.com/sbfaulkner/paperclip/commit/dd773d20d3fc555f48440c5aa6130af565df448b
Comments from Sam Stokes:
Relatedly, I needed Paperclip::Upfile to know about the application/pdf MIME type, so this one-line commit 89dcdd50... adds that. It also demonstrates that it's really easy to add new MIME types.
My understanding is that Paperclip::Upfile's ability to guess the content type doesn't normally get used, because if you upload something from a web form, then the browser supplies the content type and Paperclip just uses that. So this mostly comes up during testing (e.g. using webrat to fake out the browser).
Also (sorry for the double post but this might be useful to some people), here's a quick and dirty monkey-patch to stick in a suitable place (like
features/support/env.rb) if you need to quickly add a new content-type.Comments from Paul Cortens:
This line of code in storage.rb sets the content-type on S3 to the content-type of the originally uploaded file. If the file has been converted to another image format, this is not accurate.
key.put(nil, @s3_permissions, {'Content-type' => instance_read(:content_type)})I am guessing that we could use a method similar to content_type in upfile.rb to detect the correct content type from the format specified in the style hash. Or we could have an option to explicitly set the content-type for each style in the style hash.
What do you think?
I made a fork (http://github.com/korobkov/paperclip), where I I've added support for MIME-type resolution by magic, rather than extension, using http://github.com/minad/mimemagic gem.
It was written on pure ruby, so it will also work on non-posix-compliant systems without/usr/bin/fileutility. -
3 comments Created 5 months ago by qrushbugximagemagickxPhusion Passenger (mod_rails) Environment Issues on OSXpatchxReported by mat:
We used paperclip in our project. In production it worked great (Debian box). On our OSX boxes in development it worked great until we switched to Phusion (aka mod_rails). When running under Phusion we'd get this error:
ActionView::TemplateError (can't convert Array into String) on line #4 of vendor/plugins/active_scaffold/frontends/default/views/_form_messages.rhtml: 1: <%= render :partial => 'messages' %> 2: 3: <% unless @record.nil? %> 4: <%= error_messages_for 'record' %> 5: <% end %> vendor/plugins/active_scaffold/lib/extensions/error_messages.rb:18:in `+' vendor/plugins/active_scaffold/lib/extensions/error_messages.rb:18:in `as_full_messages'
This error is caused by our ActiveScaffold horking on an error thrown by paperclip. Paperclip is failing because ImageMagick is returning nothing - just a blank - because the environment variable $MAGICK_HOME isn't set. You see it's difficult to set the environment variables ImageMagick needs in Phusion (see http://code.google.com/p/phusion-passenger/issues/detail?id=81). There are two solutions:
- Install ImageMagick in your /usr/bin folder using Ports
- Hack apache to run a special Ruby with environment variables defined (see http://code.google.com/p/phusion-passenger/issues/detail?id=81)
Neither one of these work for us. Ports is problematic (long story) and the apache hack means we would have to run a different config for development and production.
Instead we developed a very small patch to paperclip that introduces a new parameter MAGICK_HOME alongside COMMAND_PATH. With this patch, on any Phusion box you can avoid installing ImageMagick into the /usr/bin folder and instead do this:
- Apply the patch included in this ticket
- Download and uncompress Image Magick into somewhere convenient. We put it in /usr/local/imagemagick
- Add this as an initializer in $PROJECT/config/initializers/paperclip.rb:
# config/initializers/paperclip.rb if RAILS_ENV == "development" Paperclip.options[:command_path] = '/usr/local/imagemagick/bin' Paperclip.options[:magick_home] = '/usr/local/imagemagick' end
Don't forget to restart your project after you do the above.
Our patch may be lacking in some way, it seems to work for us so far.
EDIT: Here's the correct patch for this:
Index: paperclip.rb =================================================================== --- paperclip.rb (revision 236) +++ paperclip.rb (working copy) @@ -57,7 +57,8 @@ @options ||= { :whiny_thumbnails => true, :image_magick_path => nil, - :command_path => nil + :command_path => nil, + :magick_home => nil } end @@ -70,6 +71,9 @@ end def run cmd, params = "", expected_outcodes = 0 + if options[:magick_home] + ENV['MAGICK_HOME'] = options[:magick_home] + end output = `#{%Q[#{path_for_command(cmd)} #{params} 2>#{bit_bucket}].gsub(/\s+/, " ")}` unless [expected_outcodes].flatten.include?($?.exitstatus) raise PaperclipCommandLineError, "Error while running #{cmd}"Comments
From Jon Yurek:
I was unaware of the method of passing Env variables into apps through passenger. I think a more robust solution would be a way for Paperclip to set "real" environment variables. I'll probably have a patch in a few days for this. Thanks for posting the link to the passenger ticket. This shines a light on a previous ticket about other problems with env variables and passenger.
While I can understand this issue does relate to Paperclip, I believe that the best way to handle this would be setting these environment variables in a before_filter in the controller. That way you can set them correctly through SetEnv, etc. I'm willing to be convinced otherwise, though.
From mat:
I did an upgrade to Rails 2.3.2 & Paperclip 2.2.9.1 and hit this problem again. My fix was as last time (see code below).
Can you explain in a bit more (newbie level) detail what you mean about putting this in a before_filter please?
There are a few folk out there on the web pulling their hair out on this (see http://tinyurl.com/pl98zj for instance) and it would be great to make this work, either by making the solution clearer, or failing that, including the patch.
Thanks
My mod'd paperclip/lib/paperclip.rb:
def run cmd, params = "", expected_outcodes = 0 command = %Q<#{%Q[#{path_for_command(cmd)} #{params}].gsub(/\s+/, " ")}> command = "#{command} 2>#{bit_bucket}" if Paperclip.options[:swallow_stderr] Paperclip.log(command) if Paperclip.options[:log_command] if options[:magick_home] ENV['MAGICK_HOME'] = options[:magick_home] ENV['DYLD_LIBRARY_PATH'] = options[:magick_home] + "/lib" end output = `#{command}` unless [expected_outcodes].flatten.include?($?.exitstatus) raise PaperclipCommandLineError, "Error while running #{cmd}" end output end
fivepointssolutions
Fri Jun 12 09:01:27 -0700 2009
| link
Suffering the same... +1 for documentation/solution. Thanks for beautiful library, though ;)
- Install ImageMagick in your /usr/bin folder using Ports
-
3 comments Created 5 months ago by qrushbugxJRuby: Permission denied on file movepatchxReported by Karl-Heinz Köther:
Hi,
I built a small application (one model, paperclip 2.2.5) on Ubuntu HardyHeron (4.08).
class Clip < ActiveRecord::Base has_attached_file :photo, :styles => { :small => "300x300>" }, :url => "/assets/photos/:id/:style/:basename.:extension", :path => ":rails_root/public/assets/photos/:id/:style/:basename.:extension" endWith the standard C-Ruby 1.8.6 and Rails 2.2.2 it works fine.
But the same Code with JRuby I got an error when I want to save a record.
My environment: JDK 1.6.0_11 or 1.6.0_12, JRuby 1.1.6, Rails 2.2.2
From the logs:
Errno::EACCES in ClipsController#create Permission denied - Permission denied - /tmp/stream20090216-8069-1r49ujo-0 or /home/[...]/PaperClip_JRuby/public/assets/photos/1/original/rails.png
/opt/JRuby/khk/jruby-1.1.6-22/lib/ruby/1.8/fileutils.rb:505:in `mv' /opt/JRuby/khk/jruby-1.1.6-22/lib/ruby/1.8/fileutils.rb:1395:in `fu_each_src_dest' /opt/JRuby/khk/jruby-1.1.6-22/lib/ruby/1.8/fileutils.rb:1411:in `fu_each_src_dest0' /opt/JRuby/khk/jruby-1.1.6-22/lib/ruby/1.8/fileutils.rb:1393:in `fu_each_src_dest' /opt/JRuby/khk/jruby-1.1.6-22/lib/ruby/1.8/fileutils.rb:494:in `mv' vendor/plugins/paperclip/lib/paperclip/storage.rb:44:in `flush_writes' vendor/plugins/paperclip/lib/paperclip/storage.rb:40:in `each' vendor/plugins/paperclip/lib/paperclip/storage.rb:40:in `flush_writes' vendor/plugins/paperclip/lib/paperclip/attachment.rb:152:in `save' vendor/plugins/paperclip/lib/paperclip.rb:299:in `save_attached_files' vendor/plugins/paperclip/lib/paperclip.rb:292:in `each_attachment' vendor/plugins/paperclip/lib/paperclip.rb:291:in `each' vendor/plugins/paperclip/lib/paperclip.rb:291:in `each_attachment' vendor/plugins/paperclip/lib/paperclip.rb:298:in `save_attached_files' [...]
Thanks for help
karl-heinz
Comments
Comment from Jon Yurek:
I don't know how you're running rails, but does the server/app container actually have permission to move the file?
Comment from Karl-Heinz Köther:
The server runs in my Home-Directory with my User-Permissions: khk
Rails-Envirionment: developmentStart the application with WEBrick 1.3.1
khk@duisburg:~/RAILS_ROOT/public$ lsof -i COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME java 6995 khk 36u IPv6 21612 TCP ip6-localhost:40790 (LISTEN) java 8277 khk 15r IPv6 41241 TCP *:3000 (LISTEN) khk@duisburg:~/Arbeit/Buch/RailsWay/01/PaperClip_JRuby/public$ ps aux | grep 8277 khk 8277 4.3 8.6 688192 89092 ? Sl 18:25 0:19 /opt/Java/jdk1.6.0_12/jre/bin/java -Xverify:none -da -Xmx512m -Xss1024k -classpath /opt/JRuby/khk/jruby-1.1.6-22/lib/jruby.jar:/opt/JRuby/khk/jruby-1.1.6-22/lib/bsf.jar:/opt/JRuby/khk/jruby-1.1.6-22/lib/profile.jar:/opt/NetBeans/khk/netbeans-6.5/ide10/modules/ext/mysql-connector-java-5.1.6-bin.jar -Djruby.base=/opt/JRuby/khk/jruby-1.1.6-22 -Djruby.home=/opt/JRuby/khk/jruby-1.1.6-22 -Djruby.lib=/opt/JRuby/khk/jruby-1.1.6-22/lib -Djruby.shell=/bin/sh -Djruby.script=jruby org.jruby.Main script/server webrick -e development --port 3000
When I try to upload an image I got the error:
Errno::EACCES in ClipsController#create Permission denied - Permission denied - /tmp/stream20090217-8277-1cndb7p-0 or /home/khk/RAILS_ROOT/public/assets/photos/2/original/rails.png /opt/JRuby/khk/jruby-1.1.6-22/lib/ruby/1.8/fileutils.rb:505:in `mv' [...]I've got two new files in /tmp:
$ ls -l /tmp | grep 8277 -rw------- 1 khk khk 6646 2009-02-17 18:32 stream20090217-8277-1cndb7p-0 -rw------- 1 khk khk 6534 2009-02-17 18:32 stream20090217-8277-1cndb7p-0,8277,0
And I've got a new directory in RAILS_ROOT/public:
khk@duisburg:~/RAILS_ROOT/public$ ls -R assets/ assets/: insgesamt 4 drwxr-xr-x 3 khk khk 4096 2009-02-17 18:32 photos assets/photos: insgesamt 4 drwxr-xr-x 3 khk khk 4096 2009-02-17 18:32 1 assets/photos/1: insgesamt 4 drwxr-xr-x 2 khk khk 4096 2009-02-17 18:32 original assets/photos/1/original: insgesamt 0
I get the same error with the server Mongrel 1.1.5
Comment from Gareth Townsend:
I've having the same problem under jruby.
All of my permissions seem to be in order.
There is a fix here: http://dev.nuclearrooster.com/2009/03/03/errnoeacces-permissions-error-using-paperclip/
Not sure why a cp/rm instead of a mv works, but it seems to do the trick.
-
Reported by sam:
Hi,
The latest version of of paperclip (as of 2009-05-21) has a major issue with S3 storage. Attempts to do anything related to paths or URLs (so basically everything) result in a SystemStackError: stack level too deep.
Here's a sample of output:
SystemStackError: stack level too deep from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/storage.rb:149:in `s3_path_url' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:31:in `send' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:31:in `interpolate' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:30:in `gsub' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:30:in `interpolate' from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:211:in `inject' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:29:in `each' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:29:in `inject' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:29:in `interpolate' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/attachment.rb:391:in `interpolate' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/attachment.rb:103:in `url' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:46:in `url' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:31:in `send' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:31:in `interpolate' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:30:in `gsub' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:30:in `interpolate' ... 6074 levels... from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:29:in `inject' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:29:in `interpolate' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/attachment.rb:391:in `interpolate' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/attachment.rb:112:in `path' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/storage.rb:149:in `s3_path_url' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:31:in `send' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:31:in `interpolate' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:30:in `gsub' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:30:in `interpolate' from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:211:in `inject' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:29:in `each' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:29:in `inject' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/interpolations.rb:29:in `interpolate' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/attachment.rb:391:in `interpolate' from /Users/sam/workspace/FloresFrescas.com/vendor/plugins/paperclip/lib/paperclip/attachment.rb:103:in `url'I'm guessing this has something to do with the new default style code. When I reverted to a version of the plugin from March (commit a1b39cc65) I had no problems. I've not tried any other revisions.
Cheers,
samOkay, I managed to stumble upon a fix. Simply by adding the :path to the has_attached_file it operates as it should do. I didn't realise this was a requirement, but after testing older versions and getting problems with saving to S3 I found adding :path was the only way to get anything to work.
Cheers, sam
Comments
This is still a problem. Just for clarification does specifying :path option cause the :url option to be ignored thus preventing cloud front and domain style urls?
Specifying the :path option does prevent paperclip from entering the never-ending loop.
i.e: :path => ":attachment/:id/:style/:filename"
-
Reported by Peter Suschlik
I've added I18n support for error messages:
http://github.com/splattael/paperclip/tree/translate_error_messageNow you can define translations for the errors messages in e.g. your YAML locale file:
en: paperclip: errors: attachment: size: "Invalid file size" content_type: "Unsupported content type" presence: "Cant' be blank"I fear my tests are a bit messy... I'm new to shoulda :/
Nevertheless, I hope you like the patch :)
Comments
I agree with this change, but take a look at my patch at http://github.com/joshk/paperclip which uses the proper namespacing for the errors. Currently it only supports I18n, but I will add in backward compatibility shortly.
Ok, I have added backwards compatibility and checked to make sure all tests pass. I have also added two extra error message types for the attachment size validation. Any and all comments on my fork would be appreciated.
Hi,
joshk, can you add i8n specific tests to your fork (something like what is in Peter's fork)?
We can pull your fork in once it has those tests.
Hi cpytel,
Thanks for the message, I will get this working asap. Its a bit more complicated to test as I am using the active record errors.add which then uses generate_message to create a very detailed I18n.translate call.
Will let you know when i am finished.
Thanks
Hi dmitry,
Although I created a patch for Paperclip, I need to start from scratch as I have found a bug or two which causes issues with valid? and errors. I hope to have this finished this week as work is a bit quieter now.
Sorry for the wait
Josh
Hi dmitry,
I have removed my old fork and started from scratch as my old enhancements did not seem clear and concise.
I have pushed a version which uses i18n for error messages, comes with a locale file, includes two extra message types for the size validations, and tests that i18n is being used. All tests pass and no functionality has been removed.
I still have to add backwards compatibility but I would love any and all feedback.
You can take a look at my fork here : http://github.com/joshk/paperclip
ThanksJosh
Hi Josh,
I've wrote some review comments. If you will need any more help, tell me.
Thanks,
Dmitry -
0 comments Created 5 months ago by qrushfeaturexUsing Rails' Built-in Asset Hosts for S3-stored Attachmentss3xReported by Marshall Sontag
The Problem:
I recently decided to move all of my assets, including paperclip attachments, to S3/Cloudfront. To take advantage of Rails' built-in support for multiple asset hosts, I created 4 CNAME subdomains (assets0.domain.com, assets1.domain.com, etc) that all forwarded to Cloudfront. However, because Paperclip was set to s3 storage, it would only return an S3-based URL, or it would allow me to specify only a single CNAME host. I could not use Rails' built-in asset_host settings to serve my assets.
The Solution:
Rails' built-in image_tag helper (more specifically, the image_path helper) will use the asset_host setting in your environment (if set) to calculate what the URL should be. In order to do this, it needs to be handed a relative URL (i.e. "photos/1/image.jpg"). Paperclip is not currently equipped to return a relative URL when using S3 Storage, so it needs this ability. Toward this end, I created a 4th option for the S3 :url setting (which I have called :asset_host) that returns a relative path so that Rails can do the proper URL calculation.
The Patch:
Fresh commit, complete with leading slash and 2 different asset host settings. One with bucket for S3, one without bucket for Cloudfront:
Comments
-
0 comments Created 5 months ago by qrushoptions[:whiny_thumbnails] = false doesn't runbugxReported by Toni Reina
Hi,
At present, the option :whiny_thumbnails hasn't relevance. In a line 41 in attachment.rb, there are a @whiny = options[:whiny_thumbnails] || options[:whiny] and how options[:whiny] by default is true, false || true = true.
Thanks
Comments
-
6 comments Created 5 months ago by qrushAdd Rackspace/Mosso Cloud Files supportfeaturexReported by minter
I've added support for Rackspace/Mosso Cloud Files, an S3 competitor, in my github fork (http://github.com/minter/paperclip/tree/master). I've included tests, based off of the existing S3 tests.
The Cloud Files support requires the Cloud Files Ruby gem, currently available at http://www.mosso.com/cloudfiles.jsp but hopefully soon in a more standard location.
I'm hoping this will be a useful addition to Paperclip, giving users another option for hosting their data in a cloud environment.
Comments
The Cloud Files gem is now available on github's gem server, which is much easier.
Just checking to see if there's any interest in merging this functionality in.
PeterBerkenbosch
Wed Aug 26 05:59:23 -0700 2009
| link
+1 since I probably go with mosso...
Just installed it as a plugin on my app, works perfectly.
Would it satisfy the thoughtbot creators to maybe refactor the storage part of paperclip, so that we can create plugins for paperclip that implement other storage facilities?
-
2 comments Created 5 months ago by qrushSTI subclasses share validations defined in other subclassesbugxReported by Dave Krupinski
When using paperclip in STI models each subclass contains all validations defined in any of the subclasses.
Example:
Asset < ActiveRecord::Base has_attached_file :image has_attached_file :video end
Video < Asset validates_attachment_presence :video end
Image < Asset validates_attachment_presence :image end
Image and Video will incorrectly require the presence of both a video and an image.
Comments
I have the same problem, with a Picture class inheriting from an Asset class. If I add a validates_attachment_content_type to the Picture subclass, the Asset class shares it. So this is not only between subclasses but also for the parent class.
This is because paperclip stores everything in an inheritable attribute called "attachment_definitions".
Anyway, it's probably best to try to avoid STI and rather use mixins.
A work around that seems to be working ok for me so far is to do a check for the kind of Object. E.g. I am inheriting from an Asset base and on the one subclass I want to restrict the allowed content types so I have this:
class Document < Asset validates_attachment_content_type :asset, :content_type => ['application/pdf','application/x-pdf'], :if => Proc.new { |d| d.kind_of?(Document)} end -
Reported by Dmitry Smalko
Is it possible to configure paperclip to make it move files from /tmp to store location instead of copy?
Problem is that large file takes too much time to copy. For example 1.4Gb file needs about 80sec to copy and SWFUpload goes timeout.
[...]
iostream.rb:
def to_tempfile tempfile = Tempfile.new("stream") tempfile.binmode self.stream_to(tempfile) endchanges to..
def to_tempfile self.rewind self end
On large files it works many times faster
Comments
-
When uploading a photo for a model with paperclip, everything would act like it was working properly including no errors in the log files. I had used the following initialization configuration
Paperclip.options[:command_path] = "/opt/local/bin" Paperclip.options[:whiny_thumbnails] = true Paperclip.options[:log] = true
and here is the relevant section of the 'working' logs.
[paperclip] Paperclip attachment photo on Staff initialized. [paperclip] Assigning # to photo [paperclip] Writing attributes for photo [paperclip] Post-processing photo [paperclip] Processing thumb # in the thumbnail processor. [paperclip] Processing large # in the thumbnail processor.
Everything would look like it was working fine but no files where saved or created where they should have been. After some messing around I decided to symlink the composite, identify and convert binaries to /usr/bin from the configured macports directory and comment out the command_path option in the initializer. This seems to have fixed the problem as files are now created and displayed properly.
Is this a bug in using command_path or is there another issue? This is on OS X 10.5 using apache+passenger and macports to install imagemagick
This was using paperclip 2.2.8 and I had defined the command path in config/initializers/paperclip.rb
Comments
-
0 comments Created 5 months ago by qrushCropping problems when config.cache_class = truebugxReported by Giovanni Cangiani
I'm using rjcrop
to crop paperclip images. This worked great in Rails' 2.2.2 development environment, but as soon as I went into production mode, Paperclip didn't crop the images anymore.This is what happens:
@thing = Thing.find(1) @thing.update_attributes({:crop_x=>10, :crop_y=>20, :crop_w=>130, :crop_h=>85}) @thing.paperclip_image.reprocess!It seems that Paperclip doesn't recognize the change of these instance variables (they are not in the DB, the variables are being set through attr_accessor) and thus does not see a need to reprocess the images.
A solution I found is to set
config.cache_classes = falseinconfig/environments/production.rb(it defaults totrue). Some links about similar problems can be found here.Well, maybe this is something that can be solved, I'm not quite sure…
Comments
-
0 comments Created 5 months ago by qrushImplement support for nginx upload modulefeaturexThe uploads processed by http://brainspl.at/articles/2008/07/20/nginx-upload-module are faster, but the upload format isn't the same.
Comments
-
1 comment Created 5 months ago by qrushWarn the user when no styles are defined, but a processor is.featurexIf no styles are defined, no processing is run as paperclip does not process the original file by default. If there is a processor specified but no styles, the user should be warned so there is some indication of why they are not seeing their processor working.
Comments
-
2 comments Created 5 months ago by qrushfeaturexAdded methods width, height and dir to attachmentpatchxReported by Max Lapshin
I had to get out real width and height of generated pictures and also I wanted to delete the whole directory of attachment after deleting image.
That is why I added following methods (with tests): width, heigth, dir.
Comments
Comment from Randy Schmidt
Does this work with files stored in S3? It looks like it reads the dimensions from the file everytime the size is requested, right? It looks like henrik had a solution that worked pretty well but his repo hasn't been updated in a while. He stored the dimensions in the db and then calculated the real dimensions based on the styles which seemed like a good compromise.
Just curious, is there a reason a method of determining the image dimensions hasn't been pulled into the main repo?
-
Reported by Anthony Underwood
Most of my applications have roots which are a sub_url of the root url (In passenger I use RailsBaseURI /app_name)
Therefore in my environment.rb file I use the line
config.action_controller.relative_url_root = app_namepaperclip assets do not seem to take consideration of this config.
for example, asset.url generates:
/datas/1/original/Pic.jpg?1226756334rather than
app_name/datas/1/original/Pic.jpg?1226756334I have tried with the latest version of paperclip which prepends system before datas but there is no inclusion of the app_name sub_url
this could be fixed by something like
:url => "#{ActionController::Base.relative_url_root}/system/:attachment/:id/:style/:basename.:extension"line 9 of lib/paperclip/attachment.rb
Is this something that could be looked into please?
Thanks Anthony
Comments
Comment from Jon Yurek
Turns out that different versions of Rails have different relative_url_root access methods (before 2.1 it was on AC::AbstractRequest, and after it's on AC::Base). I have added a temporary :relative_root interpolation (temporary as in I may make it automatic in the future when it's done), and it's on GitHub, but it's not 100% as I can't reliably test it.
Comment from Anthony Underwood
Could you use something like this from the openid_authentication plugin for rails that I thinks is <=2.1 and >=2.2 compatible
def requested_url relative_url_root = self.class.respond_to?(:relative_url_root) ? self.class.relative_url_root.to_s : request.relative_url_root "#{request.protocol}#{request.host_with_port}#{ActionController::Base.relative_url_root}#{request.path}" end -
3 comments Created 5 months ago by qrushfeaturexAllow file_name column to be missingpatchxReported by James Le Cuirot
I hate it when file plugins force you to have a file_name column when it’s obvious what the filename is going to be – such as when it’s something like :id.csv. This patch allows you to not have the column as long as the :path option doesn’t use :basename or :extension. I’ve added tests but I haven’t tested against S3. This approach is not ideal for S3 anyway because it calls exists? to determine whether a file is attached or not.
Comments
I'm not sure just how soon you'll be looking at this but I just tried to rebase it with the latest code and there is a small issue. It's not hard to fix, I just need to decide on the best way to do it. I'll sort it out tomorrow.
This has turned out to be harder than I thought due to the introduction of the :url interpolation. I'll try and work this out as soon as possible.
Okay I haven't tried it out much yet but the tests are passing now. It's not as simple a change as I would have liked.
The problem centres around infinite loops and the fact that you have previously used the presence of the file_name value rather than the actual existence of the file to determine whether you should return nil in certain methods. I didn't want to change that behaviour when the file_name column is present but that approach obviously won't work when the column is absent.
But then you lead to a chicken and egg scenario where exists? relies on path but path will return nil if the file doesn't exist. Similarly, url is supposed to return @default_url if the file is missing but if @path contains :url then you need the real URL to determine whether the file exists or not. Instaheadache!
After days of scratching my head, I think I've finally got it.
-
0 comments Created 5 months ago by qrushfeaturexAdd option to delegate attachment methods to the modelpatchxReported by Andrew Vit
Paperclip often doesn't fit the 1:1 user.avatar and person.portrait paradigm. I'm contributing a small but hopefully useful patch for the following scenario:
class Album < ActiveRecord::Base has_many :photos end class Photo < ActiveRecord::Base has_attached_file :photo end
To get the url for an album photo, we need to reach into the paperclip attachment attribute of the photo model, which looks messy because the photo model and the attachment should just represent the same thing:
photo = album.photos.first # Ok, this example is purposefully confusing: photo.photo.url # But it doesn't really matter what we call the attachment, # It's still some potentially confusing method chaining: photo.attachment.url photo.image.url photo.file.url photo.upload.url # Much clearer would be just: photo.url
This simple patch adds the following syntax:
class AlbumPhoto < ActiveRecord::Base has_attached_file :photo delegate_attachment_methods_for :photo end
The following methods would be available directly on the model:
photo.url photo.path photo.content_type photo.original_filename photo.size
Comments
-
1 comment Created 5 months ago by qrushbugxmust provide both :url and :path options to has_attached_filedocsxReported by David Lowenfels
has_attached_file :image, :styles => { :original => "300x>" }, :url => "/attachments/:class/:id/:style_:basename.:extension", :path => ":rails_root/public/attachments/:class/:id/:style_:basename.:extension":pathis not mentioned in the docs forhas_attached_file, only in attachment.rb I was surprised that I had to explicitly set :path (upload path) in order to get this to work properly. The POLS thing to do would be to set:path => ":rails_root/public#{:url}"if path is not explicitly supplied.Comments
Comment from Chris Roos
I just ran into this unexpected behaviour too. I changed the url option but the file was still being uploaded to the default path. In fact, it was only because I found this ticket that I was able to solve my problem.
I'm not sure what your proposed fix is but a really simple interim step might be just to update the docs for has_attached_file, stating that people should set the path option if they wish the file to be uploaded anywhere other than the default location.
-
Reported by Edward Ocampo-Gooding
I’m using paperclip rev 28a8305 and running into some unexpected behaviour with regards to whiny_thumbnail:
When ImageMagick is not installed, and whiny_thumbnail is set to true, I expected to have an error raised during resizing, but instead get this when inspecting the model’s errors:
@errors={"screenshot"=>["/var/folders/Il/IlmxVjfXGIOwab7U1JE4-E+++TI/-Tmp-/stream.18183.0 is not recognized by the 'identify' command.", "/var/folders/Il/IlmxVjfXGIOwab7U1JE4-E+++TI/-Tmp-/stream.18183.0 is not recognized by the 'identify' command."]}I added an assertion in my unit tests to look for this sort of thing and deal with it (spouting a message instructing the user to install ImageMagick), but I’d like to avoid this hack.
What do you say to patching this behaviour and making it more apparent and clear what has to be done to fix the error?
Comments
-
1 comment Created 5 months ago by qrushfeaturexuse to_param instead of id for interpolationspatchxReported by Jessy
I don't know if I am missing something, but it looks like I can't use anything else than the object id to name the attachment.
I think it would be prettier if the :id key that I use to define my attachment url was binded to the
to_parammethod of my object first so that i can override it easily.in /paperclip/attachment.rb
def self.interpolations ... :id => lambda{|attachment,style| attachment.instance.to_param || attachment.instance.id } endComments
Comment from Matt Hooks
I submitted a pull request for this just a moment ago. Adds a ":param" interpolation.
http://github.com/matthooks/paperclip/tree/master
What happens to the old files when you change your to_param method? Presumably you'll have to migrate them...
-
0 comments Created 5 months ago by qrushbugxbad return path when styles coercing image mime typespatchxWhen using paperclip has_attachment on a model and the mime type of the original image is coerced into something else using :styles and the default style is changed from :original to some else, the resulting path returns the incorrect file type by using the original mime type.
For instance
has_attached_file :image, :styles => {:thumb=> ["100x100#", :jpg], :small => ["150x150>", :jpg], :medium => ["300x300>", :jpg], :large => ["500x500>", :jpg] }, :default_style => :largeIf the original file was .png a call to model.image.path will return the .png extension even though the default style is now :large which is of type .jpg
I have attached a failing integration test case and the fix: http://gist.github.com/124457
Thanks for the great plug-in!
Comments
-
2 comments Created 5 months ago by qrushfeaturexpatchxPatch to allow per style S3 permissionss3xReported by Andrew
I have forked and patched paperclip on github at http://github.com/andrewtimberlake/paperclip/commit/5b2f2e6fb6abf9625cbf50cd59f86267cfc0a83d
This change allows you to set a hash for s3_permissions like
:s3_permissions => {:original => 'private', :thumb => 'public-read'} This is useful for a situation where a cropped thumbnail needs to be quick to download but the original file needs to be protected (and it's download might be managed through the web app itself instead of directly off S3)
You can also set a :default key in your permissions hash which will apply to all styles except those specifically stated.The original functionality is unchanged as s3_permissions can still accept a string which will apply to all styles.
Includes tests
Comments
-
Reported by Josh Pencheon
I think it would be really helpful to be able to validate an attachment as an image. At the moment, I'm doing this like this:
ALLOWED_CONTENT_TYPES = { 'MS Word' => 'doc', 'MS Excel' => 'xls', 'MS Powerpoint' => 'ppt', 'Adobe PDF' => 'pdf', 'ZIP' => 'zip', 'JPEG' => 'jpeg', 'GIF' => 'gif', 'PNG' => 'png', 'text' => 'txt' } APPLICATION_REGEXP = %r{^(x-)?application/#{ALLOWED_CONTENT_TYPES.values.join('|')}$} IMAGE_REGEXP = %r{^(image|(x-)?application)/(x-png|pjpeg|jpeg|jpg|png|gif)$} validates_attachment_presence :document validates_attachment_content_type :document, :content_type => [ APPLICATION_REGEXP, IMAGE_REGEXP, 'text/plain' ], :message => "must be: #{ALLOWED_CONTENT_TYPES.values.map{|k| '.' + k }.join(' ')}"Which is ugly, but I'm not sure what to do. However, now I need this functionality in another model, and don't want to duplicate it.
In attachment_fu, I think you can do something like this:
validates_content_type_of_attachment :imageThanks, Josh
==================
I've had a go at making a patch (it's tested): https://thoughtbot.lighthouseapp.com/attachments/70915/image_validation_additions.diff
Hope it might be helpful!
Comments
-
Reported by Michael Boutros
Hello! Recently I needed to add some custom interpolations for an attachment, and I thought the current way of having to add one through an initializer was cumbersome and kind of hackish, so I've coded up a much easier method and submitted a pull request at Github. The commit: http://github.com/michaelboutros/paperclip/commit/d693882e587dff2d737527c4298ed802b26a3b50
From the docs I wrote under #has_attachment:
+interpolations+: Takes a hash of {:name => proc|lambda} and adds each pair to the interpolations array. See Attachment#interpolations for more information on interpolations. For example:
has_attached_file :avatar, :styles => { :normal => "100x100#" }, :default_style => :normal, :url => "/:attachment/:id/:style/:user_info.:extension", :path => ":rails_root/public/:attachment/:id/:style/:user_info.:extension" :interpolations => { :user_info => proc {|attachment, style| attachment.instance.name + '_' + attachment.instance.id + '_' + style } }What does everyone think? https://thoughtbot.lighthouseapp.com/attachments/70827/easy_custom_interpolations.diff
Comments
-
1 comment Created 5 months ago by qrushbugximagemagickxPaperclip fails silently if imagemagick is not in PATHpatchxReported by Philip Hallstrom
Paperclip wasn't generating the thumbnails, but it would copy the original file into place. Worked on one host, not on another, same imagemagick version. When I ran the rake task to regenerate the thumbnails it worked.
Finally figured out that one host had a really small PATH environment that did not include /usr/local/bin (where convert/identify are).
Setting the correct path fixed the problem.
I'm not sure the best way to handle it, but a big note in the documentation or a check in Paperclip.run maybe to ensure that it can be found or some other error thrown.
I see in Paperclip.run where it is supposed to raise an error. I've double checked all my logs and see no mention of that string anywhere so it's getting eaten somewhere.
Comments
Comment from Henrik Nyh
Have this in my fork: http://github.com/henrik/paperclip/commit/5b41ceeaa264b24f15a798f00e597a597c67ca57
-
0 comments Created 5 months ago by qrushbugxIf imagemagick doesn't have PNG support, paperclip fails silentlyimagemagickxReported by Philip Hallstrom
One of my hosts has imagemagick without PNG support (argh!). When uploading PNG's none of the thumbnails would be generated.
While debugging I find that the first thing paperclip does is run this:
identify -format "%wx%h" "/tmp/stream20081113-4432-msgp7k-0" 2>/dev/null
When I run that manually I get this:
$ identify -format "%wx%h" "/tmp/stream20081113-4432-msgp7k-0" identify: no decode delegate for this image format `/tmp/stream20081113-4432-msgp7k-0'. $ echo $? 1
As near I can tell any error status beyond zero should raise an error, but no error is raised and I see nothing in the logs.
Comments
-
Reported by Giovanni Cangiani
Hi,
the to_file method for s3 Storage does not return a File object but an RightAws::S3::Key instead. This is consistent with the comment in the code (in the format most representative of the current storage), but not with what the reprocess! method in Attachment expects (an object that responds to "read" method).
I am willing to submit a patch for this but there are two ways and I'd like to know which one you prefer.
1. actually write the s3_bucket.key.data into a Tempfile and return the file
2. implement read/write methods for RightAws::S3::Key
What do you think ?Last question. Is there any foundamental reason for chosing RightAWS instead of the usual AWS::S3 ?
Thanks,
giovanni
Comments
Comment from Jon Yurek
Well, considering the method is to_file, it seems like making a Tempfile would be the right way, but in the interest of performing as few transactions over the network as possible, having the Key object respond properly to #read is likely better.
As for RightAWS... I don't have a specific reason anymore, although I did when I wrote it and I can't recall what it was and I don't have enough reason to change it now that it's written. :) Why, is there something the matter with RightAWS?
Comments from James McKinney
the Key object has a #get method, which works just like #read on File. All you would have to do is create an alias (the Key object has no #read method atm).
RightAws has some advantages over AWS::S3. For example, RightAws can connect to S3 Europe. AWS::S3 can't. RightAws makes it very easy to iterate over keys and "folders" on S3. RightAws will reconnect to S3 if S3 gives a 500 Error; AWS::S3 just fails out. RightAws in general just has a lot more methods than AWS::S3 (delete_folder, copying/moving between buckets, including US to EU, ...).
RightAws also implements the EC2, SQS, etc. APIs, so for teams who want to save on gems, RightAws is better than AWS::S3.
=======
See my comment in ticket #33: http://thoughtbot.lighthouseapp.com/projects/8794-paperclip/tickets/33#ticket-33-8
The example I give in that comment shows that, between the two options given by the reporter, the correct solution must be to write the data to a Tempfile, not just to implement #read and #write on RightAws::S3::Key. The example again is:
@user = User.new @user.avatar = User.find(1).avatar.to_file @user.save
A third alternative would require rewriting either Attachment#assign or its dependent methods to handle the assignment of a RightAws::S3::Key, which seems much more involved that just patching the #to_file method.
=======
Actually, speaking of that third alternative, it seems like if we can make it possible for RightAws::S3::Key to #include IOStream, and for it to fulfill the tests in #valid_assignment?, then we'll be on our way to a proper solution.
Comment from Jon Yurek
I think including the IOStream methods would probably work best. Getting the Key as a File would necessitate downloading it right then, which isn't always what you want (but that does make "to_file" a bit of a misnomer).
Comment from Jerry Cheung
For our use, we only call to_file when we actually wanted the file downloaded for processing. I've attached the Tempfile fix described in the first comment in case someone needs it before the final optimized fix is available.
https://thoughtbot.lighthouseapp.com/attachments/90378/s3_storage_to_file.patch
Comment from timcowlishaw
FYI - i've forked the paperclip gitrepo and applied this patch here, if it's useful for anyone.
-
0 comments Created 5 months ago by thoughtlessbugxStyles with different format are uploaded to S3 with the wrong content-typepatchxIf you have styles that convert an image (say from SVG to PNG) and are using S3 for storage, then the wrong content type will be uploaded to S3. The content type from the original will be used to set the content type for all styles.
For details see the previous lighthouse ticket here: https://thoughtbot.lighthouseapp.com/projects/8794/tickets/144-styles-with-different-format-are-uploaded-to-s3-with-the-wrong-content-type#ticket-144-6
The patch is these two commits (courtesy of S. Brent Faulkner):
http://github.com/sbfaulkner/paperclip/commit/50a156f8fe6f8f9d5c8fd51eb47506e43d7bdda4
http://github.com/sbfaulkner/paperclip/commit/dd773d20d3fc555f48440c5aa6130af565df448b
Comments
-
1 comment Created 5 months ago by bkpavanbugxrake paperclip:refresh class name error for nested modelpatchxRake task for nested ActiveRecord model eg. Namespace1::ModelName fails.
Error log:
/paperclip/tasks/paperclip_tasks.rake:5:inconst_get' /paperclip/tasks/paperclip_tasks.rake:5:inobtain_class' /paperclip/tasks/paperclip_tasks.rake:19:in `for_all_attachments' /paperclip/tasks/paperclip_tasks.rake:55Comments
fixed here: http://github.com/bkpavan/paperclip/tree/master
-
1 comment Created 5 months ago by willcodeforfoobugxProc argument given to :processors only called oncebugxI have some extra attributes on my model that has_attached_file (ProductImage), implemented using attr_accessor. I have form fields that allow the selection of these options. I want the selection of an option on the upload form to drive which processors are run on the uploaded file. e.g., checkbox for 'drop_shadow' would call the drop_shadow processor, then thumbnail.
I've implemented this as follows: http://gist.github.com/128168
This all seems to work great the first time a file is uploaded, after that it doesn't appear as though the proc is being called. I've verified this by adding a Rails logger call to Time.now.to_f
My guess is that some type of memorization is happening or something, but am not familar enough with Paperclip to verify this.
I'm using Ruby Enterprise Edition 20090520, Passenger 2.2.2 on Apache 2.2.8 on Ubuntu 8.04.2.
Comments
willcodeforfoo
Wed Sep 30 09:06:45 -0700 2009
| link
A fix/workaround with help from UVSoft in #45: http://github.com/thoughtbot/paperclip/issues/#issue/45/comment/54022
-
0 comments Created 5 months ago by christianhellstenbugxfeatureximagemagickxThe cropping is weighted at the center of the Geometry.patchxIt would be nice if the gravity in Geometry#cropping was configurable, because you don't always want the weight to be at the center.
I tried using "convert_options" to set the gravity, but it didn't work:
:convert_options => { :normal => "-gravity northwest", :small => '-gravity northwest' }This hack works, but is not configurable either:
http://snippets.aktagon.com/snippets/345-Crop-Gravity-PaperclipComments
-
4 comments Created 5 months ago by matismastersMissing uploaded files, maybe because of too many files openbugxHi guys, I'm running on Dev ENV, paperclip version 2.2.8, rails 2.1.2.
Here is the problem. Sometimes i get that error that says "Too many open files" and the server crashes, i have to start again the mongrel daemon. sometimes i think its probably when i upload many files off course. I don't think is because of reading the files, but i'm not sure. Thats one problem, and i think that probably is because of that, that i am missing files, i don't know exactly when just, one day to another, the files are gone.
Step 1, upload a photo
Step 2, Check that photo is uploaded
Note: in this step sometimes the image is not saved in all the sizes i declared on the model. Step 3, Check the thumb in the list view.
Everything seems to be fine.Days after the images are gone... Please tell me what else do you need to track the bug, maybe the mongrel log, or the development log or something. Just tell me and i'll post it
Comments
Anything and everything you can post will help with debugging this issue. http://gist.github.com
ashleym1972
Mon Oct 05 11:30:56 -0700 2009
| link
Any movement on this issue? I'm seeing this behavior in my production ENV where we will have 60,000+ open files, most of them RackMultipart temp files that are days old.
I'm using nginx + passenger, but given the RackMultipart file handling I would expect this problem anywhere.
I recently added paperclip to add a file (poster) to my model (Movie). I have a script that loops over all my movies and sets the movie's poster to a file I download from the net. Everything worked fine in dev but in prod it fails after maybe 1000 movies and I lose all the files.
Here's a gist w/, I think, all the relevant info. Is this my fault - do I need to close something?
Paperclip version = 2.3.1.1
Rails version = 2.3.4
http://gist.github.com/216541
ashleym1972
Sun Nov 08 18:40:48 -0800 2009
| link
I'm really hoping that Rails 2.3.4 solved this for us. It included a close of the multipart files that seemed to be causing our problems.
-
5 comments Created 5 months ago by UVSoftclass_caching && proc arguments to has_attached_filebugxWhen class_caching is enabled (default production configuration) and has_attached_file is called with proc values for styles hash keys :processors, :geometry, those lambdas are called only once because of:
def solidify_style_definitions #:nodoc: @styles.each do |name, args| @styles[name][:geometry] = @styles[name][:geometry].call(instance) if @styles[name][:geometry].respond_to?(:call) @styles[name][:processors] = @styles[name][:processors].call(instance) if @styles[name][:processors].respond_to?(:call) end endSuggestion is to make the following replacement in attachment.rb
def initialize ...
... @styles = options[:styles] => @styles = options[:styles].clone ... endComments
Suggested fix seems to have worked for me, thank you.
willcodeforfoo
Wed Sep 30 09:05:41 -0700 2009
| link
Yes, this fixes my report in #42, a diff:
diff --git a/vendor/plugins/paperclip/lib/paperclip/attachment.rb b/vendor/plugins/paperclip/lib/paperclip/attachment.rb index b359105..0edd750 100644 --- a/vendor/plugins/paperclip/lib/paperclip/attachment.rb +++ b/vendor/plugins/paperclip/lib/paperclip/attachment.rb @@ -33,7 +33,7 @@ module Paperclip @url = @url.call(self) if @url.is_a?(Proc) @path = options[:path] @path = @path.call(self) if @path.is_a?(Proc) - @styles = options[:styles] + @styles = options[:styles].clone @styles = @styles.call(self) if @styles.is_a?(Proc) @default_url = options[:default_url] @validations = options[:validations] @@ -41,7 +41,7 @@ module Paperclip @storage = options[:storage] @whiny = options[:whiny_thumbnails] || options[:whiny] @convert_options = options[:convert_options] || {} - @processors = options[:processors] || [:thumbnail] + @processors = options[:processors].clone || [:thumbnail] @options = options @queued_for_delete = [] @queued_for_write = {}
baldwindavid
Fri Nov 20 15:01:41 -0800 2009
| link
This worked for me when changing...
- @styles = options[:styles] + @styles = options[:styles].cloneBut I received an error with the clone on the processor.
-
4 comments Created 5 months ago by asquaredfeaturexPaperclip uses before_destroy slightly incorrectlypatchxPaperclip should probably use after_destroy to remove authenticated files, since before_destroy hooks have the power to stop the object's destruction. If paperclip's hook runs (removing the files), and then another hook stops the destruction, the object is left with a half-dead attachment. Here is a patch which addresses the issue. Essentially, changing before_destroy to after_destroy, and modifying the Attachment class to not mess with the instance properties if they are frozen (i.e. it's being destroyed).
Comments
It seems that github ate my patch. I'm probably doing something wrong. I'll throw it up somewhere else and post a link.
I've forked and applied my changes over there: http://github.com/asquared/paperclip
I'm a little unclear why as to why this has been tagged as a "feature request" and not a "bug". This could interact badly with other plugins or application code; indeed, it has in one of my applications.
-
1 comment Created 5 months ago by hardbapbugxpaperclip's rake tasks don't play nice with ActsAsParanoidpatchx -
0 comments Created 5 months ago by aselderPaperclip::Interpolations redefines classbugxThe Paperclip::Interpolations class redefines the class method it inherits from Object, and give it a different signature.
We're trying to track down a memory leak, and I'm interating through the ObjectSpace with each_object, and trying to count the objects by class. But it blows up with an error:
wrong number of arguments (0 for 2)
Override such fundamental pieces of the ruby standard library such as Object.class just strikes be as a very bad idea.
Comments
-
3 comments Created 5 months ago by praveensharmaUndefined Method `content_type' Error on RefreshbugxHey guys is there anyone who can lend a hand? I'm pulling my hair out at this issue.
Everything works fine locally, and RightAws CAN connect to S3, but when switching paperclip to S3 storage, I get the following error on refresh:
undefined method `content_type' for # /Users/praveen/Sites/percussionlab/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:57 /Users/praveen/Sites/percussionlab/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:26:in `for_all_attachments' /Users/praveen/Sites/percussionlab/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:24:in `each' /Users/praveen/Sites/percussionlab/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:24:in `for_all_attachments' /Users/praveen/Sites/percussionlab/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:22:in `each' /Users/praveen/Sites/percussionlab/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:22:in `for_all_attachments' /Users/praveen/Sites/percussionlab/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:54 /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain' /usr/local/lib/ruby/1.8/monitor.rb:242:in `synchronize' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:in `invoke_prerequisites' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `each' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with_call_chain' /usr/local/lib/ruby/1.8/monitor.rb:242:in `synchronize' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31 /usr/local/bin/rake:19:in `load' /usr/local/bin/rake:19
Is there at least any way to switch paperclip to use the AWS::S3 gem instead? I could at least try that? Anyone have any ideas?
Comments
praveensharma
Tue Jun 23 15:54:44 -0700 2009
| link
BTW, I tried this with a fresh test rails site with just one model, paperclip and s3. Same error :(
praveensharma
Thu Jun 25 11:29:01 -0700 2009
| link
Yes, apologies for starting a duplicate thread. BTW - I've confirmed this is a bug which other people are having when trying to rake refresh onto S3. A possible solution (untested ) is to do the following:
Create vendor/plugins/paperclip_s3_reprocessing/init.rb and put the following in it:
Paperclip::Attachment.class_eval do
def reprocess! new_original = Tempfile.new("paperclip-reprocess") if old_original = to_file(:original) new_original.write( old_original.respond_to?(:get) ? old_original.get : old_original.read ) new_original.rewind @queued_for_write = { :original => new_original } post_process old_original.close if old_original.respond_to?(:close) save else true end endend
-
Reported by Alain Ravet
(with Rails 2.1, and the Paperclip VERSION = "2.2.9.2")
step 1 :
class Foo < ActiveRecord::Base has_attached_file :photo endstep 2 (in the console) :
> Foo.new(:photo => 'fake.gif').photo_changed? NoMethodError: undefined method `photo_changed?' for # from /Users/jdoe/vooruit/r/vooruit-be/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:251:in `method_missing'
Comments
-
0 comments Created 4 months ago by phildarnowskyfeaturexPatch to allow option overriding of content types by file extensionpatchxHi all,
I've come up with a new option to has_attached_file, at
http://github.com/phildarnowsky/paperclip/tree/master
This option, :content_type_strategy, lets you configure Paperclip to try to deduce to content type of an uploaded file from its file extension--either across the board, or only when the uploaded file's content type is generic for some value of "generic" (i.e. application/octet-stream or similar).
I wrote this to work around an apparent bug in the version of Firefox I'm using, which claims that PDFs have the content type of "application/octet". Far as I can tell, not only is that not the right content type for a PDF, it's not a valid content type at all.
Comments are welcome.
Comments
-
0 comments Created 4 months ago by fredbugxVery Long Filename files uploaded from windows causes Errno::ENAMETOOLONGpatchxSome Windows versions allow files to have a very long file name.
in ruby method File.exist?(filename) will error on those long named files.To bypass this I applied this patch, which might be done in a better way.
diff --git a/vendor/plugins/paperclip/lib/paperclip/storage.rb b/vendor/plugins/paperclip/lib/paperclip/storage.rb index afd47e7..d349378 100644 --- a/vendor/plugins/paperclip/lib/paperclip/storage.rb +++ b/vendor/plugins/paperclip/lib/paperclip/storage.rb @@ -26,6 +26,10 @@ module Paperclip else false end + rescue Errno::ENAMETOOLONG + # ENAMETOOLONG comes from File.exist? method + # Truncate the filename to 20 chars + original_filename = original_filename[0..20] + "_#{Kernel.rand(9999999999).to_s}" end # Returns representation of the data of the file assigned to the givenComments
-
0 comments Created 4 months ago by ghazelbugx"Photo ... is not recognized by the 'identify' command." on Windowspatchx"Photo C:/DOCUME~1/user/LOCALS~1/Temp/stream.3376.0 is not recognized by the 'identify' command."
The problem is:
For users who have the "wx" env var set (like people with wxWidgets dev environments...)
set wx=FUN echo "%wx%h" "FUNh"
So, when processing this:
Paperclip.run("identify", %Q[-format "%wx%h" "#{file}"[0]])The wrong string is passed to identify. To get around this you can do:
Paperclip.run("identify", %Q[-format ^%wx^%h "#{file}"[0]])But obviously that would only work on Windows.
There's one more issue, too. If the :command_path has a space in it, Paperclip doesn't quite the path to "identify" properly. I had to change:
command = %Q<#{%Q[#{path_for_command(cmd)} #{params}].gsub(/\s+/, " ")}>to:
command = %Q<#{%Q["#{path_for_command(cmd)}" #{params}].gsub(/\s+/, " ")}>Comments
-
0 comments Created 4 months ago by dmattesbugxReprocessing with :convert_options and Proc.newpatchxMy "convert_options" looks like this:
:convert_options =>{ :all => Proc.new { |m| "-rotate #{m.rotation}" } }If I reprocess more than one image, the convert_options will not be set in the right way.
Only the first processed value of "rotation" will be used.
It's similar to https://thoughtbot.lighthouseapp.com/projects/8794/tickets/98-issue-with-new-procsMy patch is available on http://gist.github.com/140170
Comments
-
1 comment Created 4 months ago by blythedunhambugximagemagickxExternal (image magick) failures kill entire rake refresh task silent; make task more robust and verbosepatchxRunning the thumbnail refresh task as a background process I was hitting some imagemagick exceptions. These caused the whole task to abort (1 hour in). Since I was running it as a background task I didnt see the exception in the log, and it skipped printing the other error messages. I couldnt just skip over the faulty error and had to tweak the rake task to finish the rest.
I added the following features to the task:
1. catch and skip over exceptions if SKIP_ERRORS=true
2. VERBOSE=true Log Start of each ID, Log errors and exceptions (with backtrace) when they occur (so they dont get lost) and pretty print at the end.
3) LOG=DEBUG or LOG=WARN sets the ActiveRecord and Paperclip logger to stdout (useful for
4) SQL=where id > 5 Specify a where clause on selection SQL
5) ID=5 process only specified IDEXCEPTION:#d=990 NaN /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/geometry.rb:109:in `%' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/geometry.rb:109:in `cropping' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/geometry.rb:89:in `transformation_to' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/thumbnail.rb:63:in `transformation_command' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/thumbnail.rb:47:in `make' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/processor.rb:31:in `make' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/attachment.rb:332:in `post_process' /usr/lib64/ruby/1.8/fileutils.rb:505:in `inject' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/attachment.rb:330:in `each' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/attachment.rb:330:in `inject' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/attachment.rb:330:in `post_process' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/attachment.rb:327:in `each' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/attachment.rb:327:in `post_process' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/lib/paperclip/attachment.rb:223:in `reprocess!' /data/kashless/releases/20090628042702/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:56
Comments
blythedunham
Wed Jul 08 12:02:29 -0700 2009
| link
I committed my changes on this fork:
http://github.com/blythedunham/paperclip/commit/4857b60a3c3ae856dc9336d4694b5e30cb2a0cbaWould a patch submit be preferable?
-
0 comments Created 4 months ago by collimarcoafter_picture_post_process nullify referencesbugxIt is difficult to make Paperclip working with MiniExiftool.
I finally wrote this:
Photo model
belongs_to :user has_attached_file :picture after_picture_post_process :copy_exif_data private def copy_exif_data exif = MiniExiftool.new picture.queued_for_write[:original].path self.date = exif['date_time_original'] save! endI get:
Mysql::Error: Column 'user_id' cannot be null ...Without save! all works well, but self.date remains null (even if exif['date_time_original'] is NOT null).
I am really frustrated. Why does this callback makes user_id null?
Comments
-
3 comments Created 4 months ago by enricobbugxhave_attached_file matcher: undefined method 'instance_methods'patchxI'm attempting to use the have_attached_file matcher from Paperclip to test a model of mine using RSpec and Spec::Rails 1.2.6:
describe ProcessDefinition do it { should have_attached_file :definition } endWhen I attempt to run this example, I get the following error:
NoMethodError in 'ProcessDefinition should have an attachment named definition' undefined method `instance_methods' for #<ProcessDefinition:0x34eb800>After a bit of investigation, I think what's happening is that the matcher class is expecting the model class itself to be its subject but what it is actually getting is an instance. So calling
instance_methodson it blows up. This also causes problems inresponds?,has_column?, andincluded?.Here's a patch that would fix the matcher for this case, but I'm not sure if this is the best way to fix it -- after all, it could break when using another version of RSpec:
Comments
That patch has now been adjusted so that it should work whether the implicit subject is an instance or a class. Should hopefully be a lot more robust.
UPDATE: And here is a patch that applies the same fix to the other Paperclip matchers - http://gist.github.com/149244
bcardarella
Thu Oct 08 10:18:00 -0700 2009
| link
+1 on getting this pushed upstream
-
1 comment Created 4 months ago by alainravetfeaturexadd a :keep_old_files option to has_attached filepatchx(I have a patch ready at http://github.com/alainravet/paperclip/tree/keep_old_files )
Usage :
has_attached_file :avatar, :keep_old_files => true.Effect:
disable the automatic deletion of the existing files (original + resized) each time you clear or update the attachment.Usecase : images in emails.
We send notifications by emails and they include images (ex: users avatars).
If an image is updated at a later time on the server (ex: a user changes his avatar), we don't want those emails to look broken because the old images files don't exist anymore.
Comments
alainravet
Thu Jul 30 12:17:54 -0700 2009
| link
patch rebased on the latest commit (2009 July 16th)
-
1 comment Created 4 months ago by qrushbugxClearing an attachment from a new record throws an error upon savepatchxReported by Adam Grant
My Paperclip::VERSION == "2.2.9.2"
If you create a new ActiveRecord object, assign an attachment to it, clear out that attachment, and then try and save the record, the Storage#flush_writes method balks because queued_for_write was never cleared.
Example:
===============================================
class Asset < ActiveRecord::Base has_attached_file :data end asset = Asset.new asset.data = File.new("some/path", "r") asset.data.clear asset.data.save! TypeError: can't convert nil into String from ../vendor/plugins/paperclip/lib/paperclip/storage.rb:41:in `dirname' from ../vendor/plugins/paperclip/lib/paperclip/storage.rb:41:in `flush_writes' from ../vendor/plugins/paperclip/lib/paperclip/storage.rb:39:in `each' from ../vendor/plugins/paperclip/lib/paperclip/storage.rb:39:in `flush_writes' from ../vendor/plugins/paperclip/lib/paperclip/attachment.rb:142:in `save' from ../vendor/plugins/paperclip/lib/paperclip/attachment.rb:165:in `destroy' ==========================================My solution is this: modify the clear method to reset the @queued_for_write variable:
Index: lib/paperclip/attachment.rb ================================= --- lib/paperclip/attachment.rb (revision 1679) +++ lib/paperclip/attachment.rb (working copy) @@ -153,6 +153,7 @@ # use #destroy. def clear queue_existing_for_delete + @queued_for_write = {} @errors = {} @validation_errors = nil endI have a test here as well:
Index: test/attachment_test.rb =================================================================== --- test/attachment_test.rb (revision 1679) +++ test/attachment_test.rb (working copy) @@ -514,6 +514,16 @@ assert_equal nil, @attachment.path(:blah) end + context "with a file assigned but not saved yet" do + should "clear out any attached files" do + @attachment.assign(@file) + assert @attachment.valid? + assert !@attachment.queued_for_write.blank? + @attachment.clear + assert @attachment.queued_for_write.blank? + end + end + context "with a file assigned in the database" do setup do @attachment.stubs(:instance_read).with(:file_name).returns("5k.png") ===================================Sorry I can't get it into any better patch format (using git and Github and forking) than that. My machine I'm working from is quite limited from the git perspective. It's a simple fix though.
See any problems with this?
Comments
I'd like this change too.
I have a "delete picture" checkbox and http://gist.github.com/102379 would do the job. The thing is I want the checkbox do clear the picture even if you do select a file in the input. I modified the module a bit to accomplish this, but ran into this issue.
As for now a quick hack does the job for me:
picture.clear picture.instance_variable_set("@queued_for_write", {} )Thanks, qrush
-
0 comments Created 4 months ago by brunosiqueiramissing attribute: picture_file_namebugxI've been using paperclip and rubyamf in my application. When a object comes from flash and its serialized I save it to the database and it works fine. Some objects have an paperclip atachment and I pass a bytearray to it and it also works fine and the atachment is saved correctly.
Last week, I updated the last version of paperclip, and then the following error started to occur:/ActiveRecord::MissingAttributeError (missing attribute: picture_file_name):
/vendor/plugins/paperclip/lib/paperclip/attachment.rb:248:in `send' /vendor/plugins/paperclip/lib/paperclip/attachment.rb:248:in `instance_read' /vendor/plugins/paperclip/lib/paperclip/attachment.rb:170:in `original_filename' /vendor/plugins/paperclip/lib/paperclip/attachment.rb:228:in `file?'...
The weird thing is: If I create a new object and pass the attributes from the old one, it's saved correctly.
any toughts?Comments
-
0 comments Created 3 months ago by adammcnamaradefault_url being ignored when render :xmlbugxWhen format.html requests are served, default_url is called and returns a default filename.
However, when the same call is rendered using xml, the generated xml does not have the default value assigned to image_file_name.
This makes for unpredictable behavior.
Comments
-
Is there any chance we can access the rake tasks when using paperclip as a gem?
Comments
luislavena
Wed Jul 29 17:17:53 -0700 2009
| link
iphone end brightness imposed silagra acheter tamiflu tamiflu comprare tamiflu
geetarista
Wed Jul 29 17:20:49 -0700 2009
| link
Thanks for the quick reply. I was just wondering since I was able to do this with the Thinking Sphinx gem. He just puts a file with all of the tasks in lib/thinking_sphinx/tasks.rb. Then I can just include it by putting this into my rake file: require 'thinking_sphinx/tasks'
Thanks for your help!
luislavena
Fri Aug 07 08:34:09 -0700 2009
| link
wth? spam just removed my link... hey GitHub!
-
Paperclip validates_attachment_content_type not working IE8
1 comment Created 3 months ago by jyurekReported on Lighthouse:
The content type validates fine on firefox and chrome but IE8 says the content type is invalid when it actually is valid.
Comments
-
Misleading error messages when ImageMagick utilities cannot be found/invoked
4 comments Created 3 months ago by jtrupianoCurrently the Geometry.from_file() function swallows up all PaperclipCommandLineErrors and spits out a message saying: _____ is not recognized by the 'identify' command.
This is the correct error message for those cases where the 'identify' command was actually found and invoked. However, the same message is bubbled back up when the command can't even be found, and is quite misleading.
This patch alters Paperclip.run to identify the special case where the executable could not actually be found (exitcode = 127) and sets the message accordingly. Furthermore, it alters Geometry.from_file so that it doesn't swallow up PaperclipCommandLineErrors, but instead proxies the message along via a NotIdentifiedByImageMagickError.
I think this will lead to quicker troubleshooting particularly when deploying to production where the possibility of the PATH not being set up properly is higher.
The patch is here: http://github.com/jtrupiano/paperclip/commit/f103f7f91b7eb039fdb9156b9441eb7a0754f6d0
Comments
Also, I think this patch clears up Issue #7 which I've previously commented on.
I came across this blog post today that includes a reference to the misleading error message and provides a workaround. This is an issue that everyone is running into, and we could clean it up easily here...
http://www.intridea.com/posts/using-amazon-cloudfront-to-serve-assets
You are definitely right, and I will be working with this patch in the very near future.
-
validates_attachment_presence doesn't seem to work
5 comments Created 3 months ago by russellquinnI have a simple attachment in my model, but validates_attachment_presence never seems to fire.
I can freely save the model without the file.
Russell.
Comments
thoughtbot
Thu Sep 03 11:18:55 -0700 2009
| link
What version of paperclip are you using, and can you post a sample of your attachment definition?
russellquinn
Fri Sep 04 07:09:38 -0700 2009
| link
Hi,
I'm using paperclip version 2.1.2.
Here's my definition. Note that it didn't work when I used local storage before moving to S3, and I've tried various other configurations:
has_attached_file :content, :path => "foo_bar/:id/:basename.:extension", :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/amazon_s3.yml", :s3_permissions => "private", :bucket => "foobar-#{RAILS_ENV}" validates_attachment_presence :content validates_attachment_content_type :content, :content_type => "application/zip", :message => "- ZIP files only"Thanks,
Russell
"I can freely save the model without the file." I have the same problem with 2.3.x apps and paperclip 2.1.2. There are a solution for this bug? Thanks!
Eduardo Ludi
russellquinn
Tue Oct 06 08:45:02 -0700 2009
| link
I never managed to fix it.
-
AWS::S3::NoConnectionEstablished (AWS::S3::NoConnectionEstablished):
/usr/local/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/connection.rb:213:inconnection' /usr/local/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:69:inrequest' /usr/local/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:88:input' /usr/local/lib/ruby/gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/object.rb:241:instore' app/controllers/admin/events_controller.rb:32:inupdate' haml (2.0.9) lib/sass/plugin/rails.rb:19:inprocess'The plugin is working correctly with the local filesystem. Also the s3.yml file is formatted like so:
development:
access_key_id: some_number secret_access_key: some_other_number
bucket: dev-bucket production:
access_key_id: number secret_access_key: some_other_number bucket: prod-bucketThis is how it is being used in the model:
has_attached_file :image,
:styles => { :medium => "300x300>", :thumb => "100x100>", :small_thumb => "50x50"}, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :s3_headers => {"Expires" => 1.year.from_now.httpdate}, :path => ":class/:id/:attachment/:style.:extension"Also I have tested connecting to S# via the aws/s3 console and can do so with no problems. I can provide more information as needed.
Comments
thoughtbot
Thu Sep 03 10:42:54 -0700 2009
| link
Which version of paperclip are you using? When I initally put AWS::S3 in there was a connection issue. Can you please update to master or the latest gem and try again?
-
Hi,
I tried to to run the rake task to reprocess the images and this fail. See:
rake paperclip:refresh:thumbnails CLASS=Image --trace (in /var/rails/bhdasgerais) ** Invoke paperclip:refresh:thumbnails (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute paperclip:refresh:thumbnails rake aborted! undefined method `file?' for # /var/rails/bhdasgerais/vendor/plugins/paperclip/lib/paperclip.rb:236:in `data?' /var/rails/bhdasgerais/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:25:in `send' /var/rails/bhdasgerais/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:25:in `for_all_attachments' /var/rails/bhdasgerais/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:24:in `each' /var/rails/bhdasgerais/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:24:in `for_all_attachments' /var/rails/bhdasgerais/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:22:in `each' /var/rails/bhdasgerais/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:22:in `for_all_attachments' /var/rails/bhdasgerais/vendor/plugins/paperclip/tasks/paperclip_tasks.rake:44 /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /var/lib/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run' /var/lib/gems/1.8/gems/rake-0.8.7/bin/rake:31 /var/lib/gems/1.8/bin/rake:19:in `load' /var/lib/gems/1.8/bin/rake:19
I think this is a Papercilp issue
Comments
-
Just helped track down an issue where this code was in the initializer:
Paperclip.options[:command_path] = '/usr/local/ImageMagick-6.5.3/bin' Paperclip.options[:magick_home] = '/usr/local/ImageMagick-6.5.3'The error given was:
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: /tmp/stream20090908-19063-1gwjt26-0 is not recognized by the 'identify' command.>There is no reason to suspect such an issue unless one investigates the run method.
def run cmd, params = "", expected_outcodes = 0 command = %Q[#{path_for_command(cmd)} #{params}].gsub(/\s+/, " ") command = "#{command} 2>#{bit_bucket}" if Paperclip.options[:swallow_stderr] Paperclip.log(command) if Paperclip.options[:log_command] output = `#{command}` unless [expected_outcodes].flatten.include?($?.exitstatus) raise PaperclipCommandLineError, "Error while running #{cmd}" end output endCan you please change
raise PaperclipCommandLineError, "Error while running #{cmd}"to
raise PaperclipCommandLineError, "Error while running #{command}"Which would produce the much more helpful error:
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: /tmp/stream20090908-19063-1gwjt26-0 is not recognized by the '/usr/local/ImageMagick-6.5.3/bin/identify' command.>Comments
-
The docs here say "If the bucket does not exist Paperclip will attempt to create it." however I get an exception AWS::S3::NoSuchBucket.
Which is wrong, the code or the docs?
Comments
thoughtbot
Fri Sep 11 12:30:33 -0700 2009
| link
The code is wrong. It should be creating the bucket. This will be fixed shortly.
-
>> model.update_attributes!(:photo => "not_a_real_file") SQL (0.0ms) BEGIN [paperclip] Saving attachments. SQL (0.0ms) COMMIT => true >> model.photo.valid? => true
Comments
thoughtbot
Fri Sep 11 12:18:15 -0700 2009
| link
Can you post your model definition? Also, was the model valid before you tried that? What is the value of that record's photo_file_name afterwards? Paperclip will simply ignore the "not_a_real_file" value and save what it had been given previously.
>> u.avatar = File.new("/Users/jyurek/Desktop/how to pose.jpg") => #<File:/Users/jyurek/Desktop/how to pose.jpg> >> u.save => true >> u.valid? => true >> u.avatar = "not an avatar" => "not an avatar" >> u.valid? => true >> u.avatar_file_name => "how_to_pose.jpg"Hm. I would expect it to throw some sort of an error if that happened.
I looked in to how normal ActiveRecord associations work though, and if you assign a value which is not valid it simply ignores you and does not assign/save the value. I guess paprerclip is consistent here, but I'm not fond of that behavior..
-
Attachment is lost if other validation fails
0 comments Created 2 months ago by yves-voglLet's imagine we've a user object with :username and :avatar. :username is required.
If I upload a file for :avatar and leave :username blank – validation fails and :avatar is lost. So I've to enter a :username and upload the file for :avatar again. In this case it's not a problem – but imagine uploading a 100mb file. The need for reuploading it because a few information led to validation failure is a mess. And even for small files – this is an impact on usability.I'll try to find a solution and send a pull request. So take this ticket as a request for comments how to solve this issue :)
Comments
-
I use Rails 2.3.4 and Paperclip 2.1.2 and method 'validates_attachment_presence' doesn't work
Comments
-
a nice feature is, then paperclip detect a zip compression and decompress it before save. i wrote some importer and the files are large if uncompressed.
Comments
-
[pull request] support for hexdigest of attached files
0 comments Created 2 months ago by korobkovIs there someone interesting in it?
I need this functionality in my projects (for uniqueness of file content, but may also be used for other things). So I made a fork (http://github.com/korobkov/paperclip) with support of hexdigest and offer a pull request. Now it works well for me and I'm glad to share my patches with the community.
I know that paperclip project doesn't accept patches without tests, but I'm rather new in ruby and rails, and can't yet write tests myself. So, please take a look at my fork and if you are interested in it, help me with writing the test (if any needed).
I tried to follow coding style of original fork, and in many places just copied and modified original functions. May be you'll decide to rework my patches, rather than simply pulling them in. In any case it would be nice to have them in main tree (and close my fork :)), or just see some comments on them (probably, some help to me for reworking them myself).
Comments
-
difference between content_type on File and Tempfile
0 comments Created about 1 month ago by korobkovAttachments receive different content_type on creation (when they are Tempfiles and so method Paperclip::Upfile.content_type isn't invoked at all, because Upfile is included only in File, not Tempfile) and on update by rake task (
rake paperclip:refresh:metadata CLASS=some_class), when they are Files and Paperclip::Upfile.content_type is invoked as it used to be.I've fixed it in my fork (http://github.com/korobkov/paperclip/commit/fcc6a0343da2e880110d4a3f97cdf6ff656db814), but I'm a novice developer and I not only cann't yet write tests, I also don't know, what kind of test should I write to these my patches... Does anyone want to help me with this, or explain me what to do (may be with some examples)?
Comments
-
Stream file from S3 when downloading, rather than loading into memory
0 comments Created about 1 month ago by mkdynamicThis patch makes a tiny change to the way files are downloaded from S3. Rather than download the entire file to memory first (as it does currently) it uses the #stream method provided by aws-s3 to get the file in chunks. This is more memory efficient and will be slightly faster for large files:
http://github.com/mkdynamic/paperclip/commit/0bca13668d38315a284dea2b8f674efe5e3eb922
Comments
-
Resize animated gif images doesn't work properly
0 comments Created about 1 month ago by sobrinhoHi,
I'm trying to resize animated gif files without success. The patch consist to use the -coalesce option into imagemagick comand (this works when i call manually).
I think it can be used as a option into styles to not apply the -coalesce filter into images what aren't needed. Like:
has_attached_file :image, :styles => { :thumb => ['100x100#', 'coalesce'] }
I don't know if have a better way to do it, but this is a really needed feature
Comments
-
Hi,
I'm seeing a problem working with paperclip gem version 2.3.1, sqlite3, and Snow Leopard.
The updated_at value for the attachment does not take UTC into account when being stored (per my config.active_record.default_timezone setting). I'm attempting to use this timestamp as part of the filename through interpolation, and am getting 404s because the values are incorrectly parsed when I later request the URL.
I fixed this by changing line 83 of attachment.rb to read:
instance_write(:updated_at, ActiveRecord::Base.default_timezone == :utc ? Time.now.utc : Time.now)I haven't tested this against any other DB platforms, so I don't know if it's just a sqlite3 weirdness or something else. Thought I'd share though!
Comments
-
Added "host_alias" option for credential yaml when using "s3_alias_url"
0 comments Created about 1 month ago by priitHi!
I added host_alias option for credential yaml:
http://github.com/priit/paperclip/commit/51d468c3f7b785a8622087bb53c9917105b81b70Basically when using "s3_alias_url", it's nice to hold "host_alias" option in s3.yml. When both inline argument "host_alias" and yaml "host_alias" are missing, then it picks up "bucket" name as "host_alias".
It makes sense to use bucket name as host_alias as well, cos amazon recommends to use dns name for bucket name (bucket name such as image.mysite.com)
If you like this new small features to rebase to master, then I'm ready to write tests as well. All others tests are passing at the moment.
Cheers,
PriitComments
-
Tempfile fix for bug in Windows Tempfile#size breaks file size in JRuby
0 comments Created about 1 month ago by bchristensonThere is a monkeypatch for Tempfile at the bottom of lib/paperclip/iostream.rb that breaks Tempfile#size when it is run from JRuby.
It looks likes this is due to a different Tempfile implementation in JRuby. The @tmpfile instance variable is never set, so Tempfile#size always returns 0.
Tested on Windows XP and Fedora (JRuby only) with Ruby 1.8.6 and JRuby 1.3.1
Comments
-
nil.width error with styles, no error without styles...
0 comments Created about 1 month ago by omarvelous"You have a nil object when you didn't expect it! The error occurred while evaluating nil.width"
The following is my configuration
has_attached_file :file,
:path => "/photos/:photogenic_type/:photogenic_id/:id_:unique_name_:style.:extension", :url => "/photos/:photogenic_type/:photogenic_id/:id_:unique_name_:style.:extension", :default_url => "/photos/:photogenic_type/placeholder_:style.png", :styles => {:thumb => ['50#', :png], :small => ['200x400>', :png], :large => ['600x600>', :png]}It complains about nil.width... I guess the object is getting lost somewhere... However when I remove the styles... it works... This occured both on my Mac OS X Snow Leopard and on my Windows XP machines.
This is using Rails 2.3.4. Funny thing is I have another app that has been using Paperclip for a long time now, and was migrated to Rails 2.3.4, but works.
Comments
-
validates_attachment_presence fails for multiple attachments using accepts_nested_attributes_for
0 comments Created about 1 month ago by carpetthewallsIf I create a very simple application, with a product having multiple photos, and each photo has a paperclip has_attached_file, then validates_attachment_presence fails even when an image has been attached.
Interestingly, validates_attachment_content_type does work.
[code] class Product < ActiveRecord::Base
has_many :photos accepts_nested_attributes_for :photos, :allow_destroy => true endclass Photo < ActiveRecord::Base
belongs_to :producthas_attached_file :data validates_attachment_presence :data end
[/code]Comments
-
Determine file type by magic (content) rather than extension
0 comments Created about 1 month ago by korobkovI've tried to implement this in my fork (http://github.com/korobkov/paperclip ). Appreciate any comment or help with this.
Comments
-
attachment.file? should return false after destroy
0 comments Created about 1 month ago by shwoodardI think the title pretty much says it all. Let me know if I can explain further.
Thanks,
SamComments
-
Add ability to dynamically generate resized images without calling object's save method
0 comments Created about 1 month ago by drpentodeWe had the need to dynamically generate new images after an attachment is uploaded. For example, our designer might need a non-standard image size to fit a new template, or a client would be customizing their site and need a smaller version of their uploaded image.
To accomplish this, I created a gem that overrides the Paperclip::Attachment.method_missing to take resize parameters. The gem is called attachment_on_the_fly, and it's located at http://gemcutter.org/gems/attachment_on_the_fly.
>In order to use this gem, install it, require it in a model using Paperclip, and call it using methods like this:
my_obj.my_attachment.s_400_width
my_obj.my_attachment.s_400_height
my_obj.my_attachment.s_640_480I chose not to use a Processor because Processors only fire when the save method is called, and this did not work with my team's workflow.
If you find this functionality useful, feel free to integrate it with Paperclip (I can make a patch for you), send me comments, ideas, issues, etc.
Comments
-
fix for Ruby 1.9
patch: (removed)
EDIT: wasn't using the most up-to-date version ...
Comments
-
http://github.com/yickster/paperclip
I needed per instance S3 credentials for an app that can drop uploads into arbitrary S3 accounts.
This commit adds :s3_credentials => lambda support, tests, and a mention in the docs
Thanks!
Comments
-
ModelName.new.attachment_name.present? == true
1 comment Created 27 days ago by camelpunchSee title!
Comments
This is normal, Paperclip does not work like attachment_fu. When you access the attachment, you always get a Paperclip::Attachment object (so .present? always evaluates to true) !
To test if the attachment has a file attached, use attachment_name.file? -
There is no way to get original filename with special characters
3 comments Created 19 days ago by laurynasI have a case when client wants to attach file with special characters (like ä). Currently special characters are replaced to underscores. I agree that it's good practice for saving it to file system, but there is no way to get original filename when client wants to download that file and keep the name.
It would be great if it would be possible to store original filename in separate field or at least have access to unmodified original filename in before_post_process.
Comments
It can also help with russian symbols.
For now I have to disable replacement of non-latin characters with "_" to have native file names...Yes, it makes sense in many languages. Is there a way to disable replacement without patching Paperclip itself?
Sad, but it's very unlikely, as this behavior is hardcoded in Paperclip.
I just hacked it out in my fork (http://github.com/korobkov/paperclip/commit/649b07b17f4ae9561bb2b9827d271f9a90a85737), but I believe that Thoughbot will make more reliable solution. May be in next version (dev-v3.0 branch).P.S. It probably can be overriden with custom lib/paperclip/attachment.rb...
-
1 comment Created 18 days ago by mhawkinsfeaturexGenerate URLs for Private S3 ObjectspatchxI'd like to see the S3 storage module get a method to generate a URL for private S3 files. I'm working on a site that will be generating one time use URLs for customers to download with. I've seen several other people creating patches for this, so I think this could something useful to add to the core library.
AWS-S3 Docs for the S3Object#url_for method to generate a URL with a time expiring key.
http://amazon.rubyforge.org/doc/classes/AWS/S3/S3Object.html#M000045Comments
-
2 comments Created 16 days ago by dustmooIssue with s3 storage and custom processor.processorsxHi all, for some reason, when I run my style through a custom processor, and the resulting file is being stored on s3, the s3 instance of the file shows up empty.(0b)
What is odd, is that if I store the file locally everything is fine. So the processor appears to be working correctly, just the S3Object.store to S3 appears to be passing an empty file.
Can anyone else confirm this?
Thanks!
Comments
thoughtbot
Thu Nov 05 07:38:49 -0800 2009
| link
What is your processor doing? It should be returning a File (usually a Tempfile). If you can verify that the file you're passing back has data in it, you should also confirm that the file has been rewound and is ready for reading.
-
i can't upload non-images files. content-type
0 comments Created 13 days ago by mks0101i using passenger2.2.5 and rails 2.3.4. and swfupload 2.2.0
i can't upload non-images files. ex) doc, torrent, smil etc..
it happens 406 not acceptable error.
in my model
validates_attachment_content_type :attachment, :content_type => ['application/x-bittorrent', 'application/smil', 'text/plain', 'application/pdf', 'application/msword']help me!
what problems?
Comments
- bug▾
- docs▾
- feature▾
- imagemagick▾
- patch▾
- processors▾
- s3▾
- spam▾
- Apply to Selection
-
Change Color…
Preview:preview
- Rename…
- Delete












This is actually a PATH issue as it relates to apache. The problem on OSX is that apache's PATH does not include /opt/local/bin. A simple resolution to this problem is to add the following to config/environments/development.rb:
That said, the error message returned from Paperclip is very misleading. It suggests (semantically) that the 'identify' program was actually invoked and returned an error code when what's really happening is that it cannot be found. A simple check to see if $? == 127 after the failure would tell us that the 'identify' command could not be found.
I was going to fork and submit a patch, but the existing test suite fails for me on OSX (for what appears to be the exact same reason), and I wasn't prepared to walk down that rabbit hole this morning.... Essentially, I think just making that check for the shell error code and changing the exception message would save people a lot of confusion/frustration.
So I moseyed back on over to this this afternoon and whipped up a patch. The purpose of the patch is emit a more descriptive error message when an executable cannot be found on the PATH when invoking Paperclip#run. See the commit on my fork: http://github.com/jtrupiano/paperclip/commit/f103f7f91b7eb039fdb9156b9441eb7a0754f6d0
A few notables:
I've added comments to the commit referenced above that more or less echo my thoughts in the previous message here. Feel free to continue the discussion over there.