# File upload issue

**URL:** <https://www.ruby-forum.com/t/file-upload-issue/123134>\
**Category:** Rails\
**Created:** [December 14, 2007, 9:56am UTC](https://www.ruby-forum.com/t/file-upload-issue/123134 "2007-12-14T09:56:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![deliak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@deliak](https://www.ruby-forum.com/u/deliak)\
**Post date:** [December 14, 2007, 9:56am UTC](https://www.ruby-forum.com/t/file-upload-issue/123134/1 "2007-12-14T09:56:53Z")

</div>

Hi all,  
I’m running my rails app with dispatch.fcgi && lighttpd in a environment  
with memory issues(but no disk space issues). Whenever I try to upload a  
file via http (simple multipart form with input type file) which size  
is larger than memory available, the lighttpd process grows till fills  
all the memory and consequently crashes.  
What could I do to let upload files larger then memory available?  
Its is a pretty blocking issuee and I’m without a clue…

Thank you in advance for any help.

---

<div class="post-metadata">

**Author:** ![deliak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@deliak](https://www.ruby-forum.com/u/deliak)\
**Post date:** [December 14, 2007, 12:35pm UTC](https://www.ruby-forum.com/t/file-upload-issue/123134/2 "2007-12-14T12:35:16Z")

</div>

I’m shamelessly bumping my own post, but, well, really noone as a clue?  
Is there a way to make lighty buffer the file on the disk instead of  
loading it in memory?  
Should I upload the file in some other way?  
Do I have eventually to change webserver?

---

<div class="post-metadata">

**Author:** ![deliak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@deliak](https://www.ruby-forum.com/u/deliak)\
**Post date:** [December 14, 2007, 1:14pm UTC](https://www.ruby-forum.com/t/file-upload-issue/123134/3 "2007-12-14T13:14:00Z")

</div>

Well, that is a pretty sticky problem. You’ll have to decent to system  
level I guess. On debian systems you can call ‘free’ with returns the  
current memory usage. This command can of course be called in Ruby(and  
thus Rails) and then parsed to see how much memory there is still  
available.  
But I am not sure that will do you any good. As I remember from  
attachment\_fu you can ‘validate’ the file size but only _after_ it  
been uploaded. So that won’t help you. Perhaps javascript could  
intervene clientside?

Sample output free:  
$ free  
total used free shared buffers  
cached  
Mem: 239820 216752 23068 0 35112  
47252  
-/+ buffers/cache: 134388 105432  
Swap: 498004 249752 248252  
$

On Dec 14, 12:35 pm, Emanuele R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![deliak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@deliak](https://www.ruby-forum.com/u/deliak)\
**Post date:** [December 14, 2007, 1:39pm UTC](https://www.ruby-forum.com/t/file-upload-issue/123134/4 "2007-12-14T13:39:15Z")

</div>

I was not suggesting that you would validate the file size, I merely  
pointed out a problem with attachment\_fu in that respect.

As far as convincing Lighttpd to buffer the file to disk… I doubt  
you can do that.

But seriously can’t you sent a piece of Javascript which does the  
checking? Just spoke to our JS guy and he does not believe it  
can be done. In php.ini there is a variable called  
max\_post\_size(usually), perhaps a Mongrel/Apache/Lighttpd takes a  
similar parameter?

On Dec 14, 1:24 pm, Emanuele R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![deliak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9e8a1a/32.png) [@deliak](https://www.ruby-forum.com/u/deliak)\
**Post date:** [December 14, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/file-upload-issue/123134/5 "2007-12-14T13:24:07Z")

</div>

Yes it seems pretty sticky…  
anyway I do not seek a way to validate the file size since I need it to  
be uploaded even knowing that it would be larger than the memory  
available.  
To be more clear: the file going to be uploaded through the app feature  
will always be around 110Mb and the device has only 64 Mb of ram most of  
wich is obviously already taken, so loading the file in memory is out of  
question…  
There should be another way. I would hope for a way to make lighttpd  
buffer the file on disk… but anything else is apreciated.
