# Attachment\_fu and Size Issue

**URL:** <https://www.ruby-forum.com/t/attachment-fu-and-size-issue/87313>\
**Category:** Rails\
**Created:** [March 1, 2007, 4:49pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-size-issue/87313 "2007-03-01T16:49:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [March 1, 2007, 4:49pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-size-issue/87313/1 "2007-03-01T16:49:51Z")

</div>

I’ve been playing around with attachment\_fu for uploading images and  
discovered that it seems to handle the max size very strangely. It  
appears that the max size is checked after the image is resized. So  
you can upload a gigabyte file, attachment\_fu then resizes it and  
determines that it meets the size requirements.

Is there a way to limit the size of the upload? Ideally this would  
occur before loading the whole gigabyte into memory.

Eric

---

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [March 1, 2007, 6:19pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-size-issue/87313/2 "2007-03-01T18:19:02Z")

</div>

On 01 Mar 2007, at 16:49, Eric N. wrote:

> I’ve been playing around with attachment\_fu for uploading images and  
> discovered that it seems to handle the max size very strangely. It  
> appears that the max size is checked after the image is resized. So  
> you can upload a gigabyte file, attachment\_fu then resizes it and  
> determines that it meets the size requirements.

This is the best way to handle it from my point of view. The file has  
been uploaded, so it’s there on your server anyway. You could check  
the filesize using attachment\_fu’s before callback before letting the  
plugin do its resizing job.

> Is there a way to limit the size of the upload? Ideally this would  
> occur before loading the whole gigabyte into memory.

In this case, I would strongly advise you to use a clientside  
filesize check before letting them upload.

This is one of the reasons I really like to use SWFUpload for the  
uploading of files (although it has some quirks you have to take into  
account when integrating it in a rails application), you can  
effectively limit the filesize AND the types of files, as well as  
allow multiple file selection in the dialog and it does it in a  
splendid user friendly way. Add to that you can easily use it for  
having upload progress and (because it creates its own connection to  
your webserver) make it look as if the upload is “ajax’ed”. From all  
of the ajax upload workarounds, this one has pleased me the most.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![nielsene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/bc79bd/32.png) [@nielsene](https://www.ruby-forum.com/u/nielsene)\
**Post date:** [March 2, 2007, 1:46pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-size-issue/87313/3 "2007-03-02T13:46:18Z")

</div>

I agree. It’s a much better user expierence to check the size before  
uploading. You wouldn’t happen to know if there is a rails example out  
there with SWFUpload?

Thanks,

Eric
