thoughtbot / paperclip
- Source
- Commits
- Network (294)
- Issues (113)
- Downloads (23)
- Wiki (6)
- Graphs
-
Branch:
master
click here to add a description
click here to add a homepage
-
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
Please log in to comment. -
RAILS_ENVis now depreciated with Rails 3 coming out, it is now favorable to useRails.envinstead.Comments
Thanks. Made this change in a branch, will have Jon review later.
thoughtbot
Thu Jan 21 13:45:07 -0800 2010
| link
Will this be ok for older versions of Rails, Dan?
Please log in to comment.It will work for versions of Rails > 2.0. A more robust version is what I did in Shoulda later that day:
http://github.com/thoughtbot/shoulda/commit/cff740bc93375f661f665df80b727c81efb2c6d1
-
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,
DmitryPlease log in to comment.Hi Dmitry,
Thanks for the comments, I have commented on your comments and await further comment :)
Thanks
Josh
-
2 comments Created 8 months ago by qrushfeaturexs3xPatch to allow per style S3 permissionspatchxReported 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
-
2 comments Created 6 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
Please log in to comment.So I ran into this problem in a different way. My database seeds (which include images) didn't work on another machine (probably due to a different version of ImageMagick) and trying to .clear the attachment after finding out it was not .valid? triggered the same error. My fork of paperclip has basically the same fix as above but adds different tests. Please merge either one.
-
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
Please log in to comment. -
3 comments Created 8 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.
Please log in to comment.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.
-
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
Please log in to comment.Comment from timcowlishaw
FYI - i've forked the paperclip gitrepo and applied this patch here, if it's useful for anyone.
-
1 comment Created 8 months ago by christianhellstenfeaturexpatchximagemagickxThe cropping is weighted at the center of the Geometry.bugxIt 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
-
2 comments Created 8 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
Please log in to comment.+1 - We ran into this and spent twenty minutes tracing down the cause. Our case was even weirder in that we had multiple formats defined and the move blew up when trying to move the original file the second time as it didn't exist. The exception raised in the patch would have been most helpful.
-
1 comment Created 7 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
Please log in to comment.I fixed these issues in this branch: http://github.com/ghazel/paperclip
-
1 comment Created 7 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
Please log in to comment.
alainravet
Thu Jul 30 12:17:54 -0700 2009
| link
patch rebased on the latest commit (2009 July 16th)
-
3 comments Created 8 months ago by qrushimagemagickxbugxPhusion 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 endPlease log in to comment.
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
-
9 comments Created 8 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?
Seems reasonable, though you'd probably need to take that up with them.
nicholaswyoung
Tue Jan 05 11:28:58 -0800 2010
| link
+1 for Cloud Files integration. Until then, I'll be using Minter's fork.
mediaslave
Thu Jan 07 13:28:46 -0800 2010
| link
+1 for Cloud Files integration
Please log in to comment.
pjleonhardt
Mon Feb 01 17:47:54 -0800 2010
| link
+1 for Cloud Files integration
-
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"
rebelcolony
Wed Nov 25 01:07:06 -0800 2009
| link
sorry, how would i add path to:
has_attached_file :image, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :styles => { :thumb => "190x124>", :large => "400x300>" }
Please log in to comment.
rebelcolony
Wed Nov 25 01:22:37 -0800 2009
| link
ok just added the :path so
has_attached_file :image, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :path => ":attachment/:id/:style.:extension", :styles => { :thumb => "190x124>", :large => "400x300>" }
and seems to work. -
Determine file type by magic (content) rather than extension
0 comments Created 4 months ago by korobkovI've tried to implement this in my fork (http://github.com/korobkov/paperclip ). Appreciate any comment or help with this.
Comments
Please log in to comment. -
3 comments Created 8 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)} endPlease log in to comment.That worked for me, strangely, it works perfectly fine WITHOUT the work around on OS X. Very odd error.
-
0 comments Created 8 months ago by qrushs3xUsing Rails' Built-in Asset Hosts for S3-stored AttachmentsfeaturexReported 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
Please log in to comment. -
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.
Please log in to comment.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 -
0 comments Created 8 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
Please log in to comment. -
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
Please log in to comment. -
I've checked the code and the method is correct:
# Returns the timestamp as defined by the <attachment>_updated_at field def timestamp attachment, style attachment.instance_read(:updated_at).to_s endWhen using it:
Contest.last.videobrief.path => "videobriefs/90/2009-12-04 07:02:43 -0800_original.flv" Contest.last.videobrief.url => "http://d3pqlvx29u0inx.cloudfront.net/videobriefs/90/2009-12-04 07:02:43 -0800_original.flv?1259938963" Contest.last.videobrief.updated_at => 1259938963 Contest.last.videobrief.updated_at.to_s => "1259938963" Contest.last.videobrief_updated_at
=> Fri, 04 Dec 2009 07:02:43 PST -08:00 Contest.last.videobrief.updated_at
=> 1259938963 Contest.last.videobrief_updated_at => Fri, 04 Dec 2009 07:02:43 PST -08:00 Contest.last.videobrief.updated_at => 1259938963It seems like the interpolations code isn't used.
Comments
Please log in to comment.
oscardelben
Wed Dec 09 02:15:22 -0800 2009
| link
def timestamp attachment, style;
attachment.instance_read(:updated_at).to_s; endIt should use to_i, not to_s
-
3 comments Created 8 months ago by qrushimagemagickxgs not found during tests on os-xbugxReported 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
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:
config.after_initialize do require 'paperclip' Paperclip.options[:command_path] = '/opt/local/bin' endThat 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:
- prior to my patch, running "ruby test/paperclip_test.rb" by itself actually yielded 4 failures all relating to $? being nil. There are likely (pending some cross platform differences) cross-test dependencies in your test suite as these failures do not occur when running the whole test suite (rake test). The mocking I used to fix that is also used to validate my changes.
- I have updated one line in Geometry#from_file. However, I was unsure why you were swallowing up the PaperclipCommandLineError in the first place. Seems that there's no way the subsequent call to #parse would pass when this is the case. I suspected (though am totally unsure) it was because you wanted to limit the exceptions that could be raised from Geometry#from_file to those of the type NotIdentifiedByImageMagickError. As such, I basically wrapped the original PaperclipCommandLineError in a NotIdentifiedByImageMagickError instead. However, this feels weird to me as the semantics of "PaperclipCommandLineError" seem more in line with the actual error than "NotIdentifiedByImageMagickError". I wanted to ask you if you had a preference for one over the other. Obviously, if we change it to PaperclipCommandLineError (which I think is more appropriate), we'd want to add a test to geometry_test.rb to distinguish between the two possible exception types.
- several tests (distinct from the tests mentioned in my previous bullet point) in the full test suite fail because certain fixture data (specifically the pdfs) do not exist in the repo. Perhaps we should add a rake task to download those if they're not to be included in the repository???
Please log in to comment.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.
-
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
Please log in to comment.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.
masterkain
Sun Nov 29 01:32:49 -0800 2009
| link
still no love..
I've switched MIME-type resolution from http://github.com/minad/mimemagic to http://github.com/Narnach/file_wrapper, which wraps /usr/bin/file...
Please log in to comment.I implemented correct content_type detection with file --mime-type command:
http://github.com/monde/paperclip/commit/2ca52df1aa45a8a9cb3d086a6be77168b7f5be52The file command is able to determine a wide range of content types beyond what is possible with a simple check of a file name's extention.
-
3 comments Created 8 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
Please log in to comment.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.
-
0 comments Created 8 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
Please log in to comment. -
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
Please log in to comment. -
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 8 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
Please log in to comment. -
1 comment Created 8 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 8 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?
Please log in to comment.Comment from Max Lapshin
You are right, it will work only with local images. So, it seems that this code should be used only in local storage
-
0 comments Created 8 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
Please log in to comment. -
2 comments Created 8 months ago by qrushdocsxmust provide both :url and :path options to has_attached_filebugxReported 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.
Please log in to comment.Agreed this is a docs issue more than anything. Need to at least mention the :path option.
-
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
Please log in to comment.
- bug▾
- docs▾
- feature▾
- imagemagick▾
- patch▾
- processors▾
- rails3▾
- s3▾
- spam▾
- Apply to Selection
-
Change Color…
Previewpreview
- Rename…
- Delete



