thoughtbot / paperclip

Easy file attachment management for ActiveRecord
https://thoughtbot.com
Other
9.01k stars 2.43k forks source link

frustrating 'nothing happens' issue #305

Closed inspire22 closed 13 years ago

inspire22 commented 13 years ago

in my initializer:

Paperclip.options[:command_path] = "/usr/local/bin"

Paperclip.options[:whiny_thumbnails] = true
Paperclip.options[:log] = true

I've got my file field defined, on the model, the image is being posted with the form

Still nothing happens, I just get one line from paperclip: [paperclip] Saving attachments.

Processing by ItemController#edit as HTML Parameters: {"kind"=>"poem", "commit"=>"Submit Poem", "after_to"=>"", "authenticity_token"=>"o1ZX05qub/xbMup3aJ9UFP9CsKghQSDzxR8c0cuT9Pc=", "utf8"=>"\342\234\223", "id"=>"396", "item"=>{"rendered"=>"test", "title"=>"shrug", "notes"=>"", "collab"=>"", "myimage"=>#File:/var/folders/qb/qbhkEi1YGNiB-2iIABpfMU+++TI/-Tmp-/RackMultipart20100920-44129-u8gbqm-0, "align"=>"Left", "tag_list"=>"", "draft_id"=>"", "question"=>"What did you think"}}

has_attached_file :myimage, :styles => {:large => ["600x600>",'jpg']}, :path => ':rails_root/public/images/ext/:class/:my_partition.jpg', :url => '/images/ext/:class/:my_partition.jpg', :convert_options => {:all => "-auto-orient -strip -quality 89"} #-depth=8  no -depth option?

Imagemagick/Convert exists. I even tried linking them to /usr/bin from /usr/local/bin.

.path works:

Item.find(396).image.path => "/Users/inspire/Dropbox/newap/public/images/ext/items/0/396.jpg"

Any way to get more info from paperclip as to what could be going wrong? I'm having a very frustrating time with it, and starting to wish I'd just coded my own custom thumbnail generator...

jyurek commented 13 years ago

Could you also add "Paperclip.options[:log_command] = true" to your initializers? That will log the command it's using if you're not already.

What exactly isn't working? Do the files exist on the filesystem where you expect and contain what you expect? What does the #url command give? Are the models saving correctly aside from paperclip? No validation errors? You say ImageMagick is available, where is it installed, of not /usr/local/bin? Is that path available to your app?

inspire22 commented 13 years ago

Thanks for your help, sorry for my grumpiness.

I got it to work in the console, using the tempfile from my browsing. So thats no the issue

i.image = f
=> #<File:/var/folders/qb/qbhkEi1YGNiB-2iIABpfMU+++TI/-Tmp/RackMultipart20100920-44129-u8gbqm-0>
>> i.save
  SQL (4.0ms)  BEGIN
  SQL (2.8ms)  UPDATE `items` SET `colors` = '--- \n- hi\n', `image_file_name` = 'RackMultipart20100920-44129-u8gbqm-0', `updated_at` = '2010-09-21 03:06:46' WHERE (`items`.`id` = 2)

I added your log command to the initializers, but still nothing is printed. It's not getting that far for some reason.

Given that it works in the console, but not via mongrel (nor webrick I also tried), any ideas where to further narrow the debugging?

Thanks! :)

jyurek commented 13 years ago

Actually, getting it to work from the command line doesn't really mean too much, if we're talking about PATH issues. But it's usually not a problem if you're using mongrel. Hmm. So just to satisfy my curiosity, what are the answers to all the questions above? They can be useful to debug the issue.

inspire22 commented 13 years ago

Command line path issues - really? Shouldn't be much difference with console @record.image = <Tmpfile> than web server creating and assigning to @record.image, eh?

url gives: "/images/ext/items/0/2.jpg?1285038405" I'm naming it based on the object id, so the actual file name isn't used anywhere.

Tmpfile is created fine (its left behind so I'm able to identify/convert/etc it after the controller fails)

Imagemagick is installed to /usr/local/bin. I tried symlinking it to /usr/bin to see if that would help, since that seems to be the default checked.

Validations all pass, record is shown as saved in the logfile.

The person I ran the tests with in the console is the same person running the web server instance, so access to the directories should work. All are accessible by anyone anyways...

inspire22 commented 13 years ago
[paperclip] file '--mime-type' '/var/folders/qb/qbhkEi1YGNiB-2iIABpfMU+++TI/-Tmp-/RackMultipart20100920-44129-u8gbqm-0' 2>/dev/null
[paperclip] identify '-format' '%wx%h' '/var/folders/+a/+aeji4GfHRCf-OCtGR-VrU+++TI/-Tmp-/stream,83479,0[0]' 2>/dev/null
[paperclip] convert '/var/folders/+a/+aeji4GfHRCf-OCtGR-VrU+++TI/-Tmp-/stream,83479,0[0]' '-resize' '600x600>' '-auto-orient' '-strip' '-quality' '89' '/var/folders/+a/+aeji4GfHRCf-OCtGR-VrU+++TI/-Tmp-/stream,83479,0,83479,0.jpg' 2>/dev/null
  SQL (4.6ms)  BEGIN
  SQL (3.6ms)  UPDATE `items` SET `colors` = '--- \n- hi\n' WHERE (`items`.`id` = 2)
[paperclip] Saving attachments.
[paperclip] saving /Users/kevin/Dropbox/newap/public/images/ext/items/0/2.jpg
[paperclip] saving /Users/kevin/Dropbox/newap/public/images/ext/items/0/2.jpg
  SQL (6.4ms)  COMMIT
jyurek commented 13 years ago

No, there shouldn't be much difference, but sometimes the server software isn't running in the same environment (see: passenger). You're using mongrel, though, so if you're on the console as the same user you should be ok.

About the URL, is the 0 in there actually correct? If that's an ID, I wouldn't expect that to be right.

So, I notice that you're saving both styles as the same file, according to the log you pasted. Normally, you'd use the :style interpolation to separate them. What exactly isn't working, anyway? Are you not seeing any images in the browser? Are you not seeing the styles?

inspire22 commented 13 years ago

Phew, I figured it out!

When the server does the processing, paperclip didn't seem to get the file. It only has the standard '[paperclip] Saving attachments.' line, no convert/identify is ever called.

I hacked the gem to add more debug lines to see if I can figure it out that way. [paperclip] testing valid_assignment? [paperclip] String [paperclip] false

Hmm, thats strange! Turns out my aggressive before_filter to remove html from inputs had a bug where it was to_s'ing all values. So all paperclip got was .image = '#'

Still, a debug message in attachment#valid_assignment? that showed a 'log' msg if a non-file was passed would have helped.

Thanks so much for your help! :)

jyurek commented 13 years ago

Oh wow, that's a tough one. Glad you figured it out! I think more checks like that are probably a good idea! Thanks.