# Attachment\_fu issues

**URL:** <https://www.ruby-forum.com/t/attachment-fu-issues/111709>\
**Category:** Rails\
**Created:** [August 10, 2007, 12:05am UTC](https://www.ruby-forum.com/t/attachment-fu-issues/111709 "2007-08-10T00:05:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![P.F.Pluto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/85f322/32.png) [@P.F.Pluto](https://www.ruby-forum.com/u/P.F.Pluto)\
**Post date:** [August 10, 2007, 12:05am UTC](https://www.ruby-forum.com/t/attachment-fu-issues/111709/1 "2007-08-10T00:05:12Z")

</div>

Relying largely on Mike C.'s guidance:

[http://clarkware.com/cgi/blosxom/2007/02/24](http://clarkware.com/cgi/blosxom/2007/02/24)

I’ve had limited success with attachment\_fu. I’m able to upload  
andsubsequently redisplay images through the browser. But, a few  
things aren’t working right:

1. Image size is sometimes 0 and sometimes actual size (more often 0).  
Can’t find a pattern, testing with jpg, png, gif with Firefox and IE.  
I’ve had to set the :size option to allow 0, otherwise validation  
prevents images from uploading (again, most of the time but not  
always).

2. Images don’t resize even though option is set in model.

3. Thumbnails aren’t generated even though option is set in model.  
Only the original image at it’s original size with it’s original name  
is stored.

Below is my model. I’m pretty new to rails so it’s entirely possible  
I’ve done something idiotic. This is happening on Windows XP w/  
InstantRails (haven’t tried it in my hosted environment yet).

class Mugshot \< ActiveRecord::Base

has\_attachment :content\_type =\> :image,  
:storage =\> :file\_system,  
:size =\> 0.kilobyte…2.megabytes,  
:resize\_to =\> [50, 50],  
:thumbnails =\> { :thumb =\> [50, 50], :geometry =\> ‘x50’ },  
:processor =\> ‘Rmagick’  
validates\_as\_attachment

end

---

<div class="post-metadata">

**Author:** ![P.F.Pluto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/85f322/32.png) [@P.F.Pluto](https://www.ruby-forum.com/u/P.F.Pluto)\
**Post date:** [August 10, 2007, 10:01am UTC](https://www.ruby-forum.com/t/attachment-fu-issues/111709/2 "2007-08-10T10:01:49Z")

</div>

On 10 Aug 2007, at 00:04, P.F.Pluto wrote:

> is stored.  
> There are a number of possibilities.

1. and 3) are related to 1), so it has to do with the images you’re  
uploading. Attachment\_fu will determine if it’s an image by checking  
the MIME type. This can lead to images not being recognized as images  
if the browser doesn’t upload them with the correct MIME type or if  
your images are corrupt.

To give you an example: when using a solution like SWFUpload to  
upload images, all files will be streamed as application/octet-  
stream, attachment\_fu won’t recognize them as being images. In this  
case, you need to “preprocess” the upload by mapping the extension of  
the file to a mime type before passing it on to attachment\_fu for  
thumbnailing.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![P.F.Pluto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/85f322/32.png) [@P.F.Pluto](https://www.ruby-forum.com/u/P.F.Pluto)\
**Post date:** [August 10, 2007, 11:46pm UTC](https://www.ruby-forum.com/t/attachment-fu-issues/111709/3 "2007-08-10T23:46:40Z")

</div>

Thanks for your reply Peter. I was able to get 1) solved using the  
sleep fix. Eric N.'s change to attachment\_fu also fixed the  
problem for me (both fixes described in this post):

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/2150d2ebe267545a/dc13f21b1a4a87fc?lnk=gst&q=attachment\_fu+sleep&rnum=1#dc13f21b1a4a87fc](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/2150d2ebe267545a/dc13f21b1a4a87fc?lnk=gst&q=attachment_fu+sleep&rnum=1#dc13f21b1a4a87fc)

However, I still haven’t been able to get thumbnails or resizing  
working on my Windows development box.

I deployed to my OCS Solutions shared host and am not having any of  
the problems. I’m starting to wonder if rails development and windows  
don’t mix. Maybe I should bite the bullet and load linux or get a Mac.

---

<div class="post-metadata">

**Author:** ![P.F.Pluto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/85f322/32.png) [@P.F.Pluto](https://www.ruby-forum.com/u/P.F.Pluto)\
**Post date:** [August 10, 2007, 11:53pm UTC](https://www.ruby-forum.com/t/attachment-fu-issues/111709/4 "2007-08-10T23:53:41Z")

</div>

Oops, the post was from me, inadvertantly using an alternate gmail  
account of mine.

Thanks again for your reply Peter.
