# File Upload without the Temp File Copy

**URL:** <https://www.ruby-forum.com/t/file-upload-without-the-temp-file-copy/153504>\
**Category:** Mongrel\
**Created:** [November 18, 2008, 3:30am UTC](https://www.ruby-forum.com/t/file-upload-without-the-temp-file-copy/153504 "2008-11-18T03:30:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![axyd80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@axyd80](https://www.ruby-forum.com/u/axyd80)\
**Post date:** [November 18, 2008, 3:30am UTC](https://www.ruby-forum.com/t/file-upload-without-the-temp-file-copy/153504/1 "2008-11-18T03:30:13Z")

</div>

Is it possible to upload file directly into database?  
Without creation the extra temp file on the disk.

Thanks! 🙂

---

<div class="post-metadata">

**Author:** ![axyd80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@axyd80](https://www.ruby-forum.com/u/axyd80)\
**Post date:** [November 18, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/file-upload-without-the-temp-file-copy/153504/2 "2008-11-18T17:06:51Z")

</div>

Is there a reason why you are avoiding the filesystem for storage?

Michael

---

<div class="post-metadata">

**Author:** ![axyd80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@axyd80](https://www.ruby-forum.com/u/axyd80)\
**Post date:** [November 18, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/file-upload-without-the-temp-file-copy/153504/3 "2008-11-18T18:19:50Z")

</div>

On Tue, Nov 18, 2008 at 8:37 AM, Alexey P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> stream to it’s destination without lost performance on not needed IO  
> operations.

You could look at the Ruby code that produces the temporary files, and  
change it.  
It is in method CGI::QueryExtension#read\_multipart in cgi.rb  
(/usr/lib/ruby/1.8/cgi.rb on my machine)

Stephan

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Mongrel-users mailing list  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/mongrel-users](http://rubyforge.org/mailman/listinfo/mongrel-users)

–  
Stephan W.

→ [http://stephan.sugarmotor.org](http://stephan.sugarmotor.org)  
 → [http://www.thrackle.org](http://www.thrackle.org)  
 → [http://www.buckmaster.ca](http://www.buckmaster.ca)  
 → [http://www.trafficlife.com](http://www.trafficlife.com)  
 → [http://stephansmap.org](http://stephansmap.org) – [blog.stephansmap.org](http://blog.stephansmap.org)  
 → [http://loggingit.com](http://loggingit.com) – [blog.loggingit.com](http://blog.loggingit.com)

---

<div class="post-metadata">

**Author:** ![axyd80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@axyd80](https://www.ruby-forum.com/u/axyd80)\
**Post date:** [November 18, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/file-upload-without-the-temp-file-copy/153504/4 "2008-11-18T17:37:31Z")

</div>

Michael D’Auria wrote:

> Is there a reason why you are avoiding the filesystem for storage?
> 
> Michael

Yes, i’m using abstract storage interface, that can be implemented as  
local file system, remote file system, distributed file system,  
database, cache.

In this case the temp file is not needed. I can just switch the input  
stream to it’s destination without lost performance on not needed IO  
operations.

---

<div class="post-metadata">

**Author:** ![axyd80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@axyd80](https://www.ruby-forum.com/u/axyd80)\
**Post date:** [November 18, 2008, 6:46pm UTC](https://www.ruby-forum.com/t/file-upload-without-the-temp-file-copy/153504/5 "2008-11-18T18:46:50Z")

</div>

On Nov 18, 2008, at 9:19 AM, Stephan W. wrote:

> > In this case the temp file is not needed. I can just switch the input  
> > stream to it’s destination without lost performance on not needed IO  
> > operations.
> 
> You could look at the Ruby code that produces the temporary files, and  
> change it.  
> It is in method CGI::QueryExtension#read\_multipart in cgi.rb  
> (/usr/lib/ruby/1.8/cgi.rb on my machine)

Mongrel doesn’t actually use CGI.rb, thats only rails. You want to  
look in http\_request.rb and patch the code that writes to a tmpfile  
and have it write to wherever you want:

[http://mongrel.rubyforge.org/browser/trunk/lib/mongrel/http\_request.rb#L47](http://mongrel.rubyforge.org/browser/trunk/lib/mongrel/http_request.rb#L47)

Cheers-

Ezra Z.  
removed\_email\_address@domain.invalid
