# Upload module 2.0.4

**URL:** <https://www.ruby-forum.com/t/upload-module-2-0-4/145220>\
**Category:** NGINX\
**Created:** [August 6, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/upload-module-2-0-4/145220 "2008-08-06T22:13:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valery\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ee7513/32.png) [@Valery\_K](https://www.ruby-forum.com/u/Valery_K)\
**Post date:** [August 6, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/upload-module-2-0-4/145220/1 "2008-08-06T22:13:45Z")

</div>

Changes (2008-08-06):

- Fixed bug: location configuration of upload\_set\_form\_field and  
upload\_pass\_form\_field was not inheritable from server configuration.
- Added feature: directive upload\_aggregate\_form\_field to pass  
aggregate properties of a file like file size, MD5 and SHA1 sums to  
backend.
- Fixed bug: missing CRLF at the end of resulting body.
- Change: optimized out some unnecessary memory allocations and  
zeroing.

See module page for details:  
[http://www.grid.net.ru/nginx/upload.en.html](http://www.grid.net.ru/nginx/upload.en.html)

I also have found that there are no issues with interaction between  
upload module and upload progress module, so they could be nicely used  
together.

---

<div class="post-metadata">

**Author:** ![Valery\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ee7513/32.png) [@Valery\_K](https://www.ruby-forum.com/u/Valery_K)\
**Post date:** [August 7, 2008, 1:11am UTC](https://www.ruby-forum.com/t/upload-module-2-0-4/145220/2 "2008-08-07T01:11:37Z")

</div>

On 8/6/08, Valery K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Hi there - how could this work with PUT method?

Basically I need to be able to PUT files of various sizes - from a few  
bytes to 2GB, maybe more someday.

We’d like the webserver to accept it via PUT and then feed the  
location of the file to PHP so PHP can do the post processing (file  
rename, input the metadata into database, etc.)

I want to use nginx for this. Not sure if a third party module like  
yours is required or not. Right now, I can do a simple single file PUT  
to a php script and use php://input to open the stream. However large  
files will consume all the PHP script resources I believe if it has to  
accept all the data (unless the upload client is smart enough to spoon  
feed it in certain chunks…)

Is this understandable? I’ve kind of gone off the deep end here now.

---

<div class="post-metadata">

**Author:** ![Valery\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ee7513/32.png) [@Valery\_K](https://www.ruby-forum.com/u/Valery_K)\
**Post date:** [August 7, 2008, 8:44am UTC](https://www.ruby-forum.com/t/upload-module-2-0-4/145220/3 "2008-08-07T08:44:15Z")

</div>

mike ha scritto:

> On 8/6/08, Valery K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> Hi there - how could this work with PUT method?

You don’t need this module, if the request body contains the whole file.

The upload module is usually useful for POST requests, since the request  
body is multipart/form-data encoded, when sent by browsers.

If you are using PUT, then probably the client is under your control.

> files will consume all the PHP script resources I believe if it has to  
> accept all the data (unless the upload client is smart enough to spoon  
> feed it in certain chunks…)

This is not what the upload module does: the upload module has been  
written for decoding multipart/form-data request bodies “on the fly”.

If the file is very large, there is nothing that can be done now.

How do you read the file from PHP?  
If you don’t have to read the whole file (as it usually is), then this  
should not be a big problem.

As an example, for renaming the file, you don’t need to read the file  
from PHP: let Nginx store the file in a temporary file and just rename  
that file.

> Is this understandable? I’ve kind of gone off the deep end here now.

Manlio P.

---

<div class="post-metadata">

**Author:** ![Valery\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ee7513/32.png) [@Valery\_K](https://www.ruby-forum.com/u/Valery_K)\
**Post date:** [August 7, 2008, 9:00am UTC](https://www.ruby-forum.com/t/upload-module-2-0-4/145220/4 "2008-08-07T09:00:39Z")

</div>

On 8/6/08, Manlio P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How do you read the file from PHP?

well right now php://input - it comes through via stdin

> As an example, for renaming the file, you don’t need to read the file from  
> PHP: let Nginx store the file in a temporary file and just rename that file.

okay so i need to tune nginx to accept large client uploads…

---

<div class="post-metadata">

**Author:** ![Valery\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ee7513/32.png) [@Valery\_K](https://www.ruby-forum.com/u/Valery_K)\
**Post date:** [August 7, 2008, 9:37am UTC](https://www.ruby-forum.com/t/upload-module-2-0-4/145220/5 "2008-08-07T09:37:34Z")

</div>

mike [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi there - how could this work with PUT method?

It can’t. Use built in DAV module.

> Is this understandable? I’ve kind of gone off the deep end here now.

In this way even DAV module can’t do it, I suppose. Why are not happy  
with  
POST?

---

<div class="post-metadata">

**Author:** ![Valery\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ee7513/32.png) [@Valery\_K](https://www.ruby-forum.com/u/Valery_K)\
**Post date:** [August 7, 2008, 10:27am UTC](https://www.ruby-forum.com/t/upload-module-2-0-4/145220/6 "2008-08-07T10:27:20Z")

</div>

On 8/7/08, Valery K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> POST?  
> POST isn’t reliable for large files and I don’t believe (without some  
> major inspection) it can support resuming files, etc.

PUT seems like the appropriate method for large files, and skipping  
the encoding step. I already have a PHP script which will process it  
too, and tons of different browser applets to choose from that will  
handle it.

People will be uploading files of various sizes from various  
connection speeds and geographies, so it has to support resuming,  
gracefully from timeouts or hitting the pause button etc.

It does not seem like POST will do that; not to mention the server  
handles POST differently than PUT.

I believe nginx’s DAV support will work just need to test out large  
files, pick a specific upload applet, etc.

---

<div class="post-metadata">

**Author:** ![Valery\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ee7513/32.png) [@Valery\_K](https://www.ruby-forum.com/u/Valery_K)\
**Post date:** [August 7, 2008, 10:58am UTC](https://www.ruby-forum.com/t/upload-module-2-0-4/145220/7 "2008-08-07T10:58:59Z")

</div>

mike [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> handles POST differently than PUT.
> 
> I believe nginx’s DAV support will work just need to test out large  
> files, pick a specific upload applet, etc.

I agree with you. The proper uploader should be able to handle partial  
uploads. This would be a nice challenge for me to implement chunked  
transfer encoding and byte ranges support for PUT.

May be I’ll consider this later.

---

<div class="post-metadata">

**Author:** ![Valery\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ee7513/32.png) [@Valery\_K](https://www.ruby-forum.com/u/Valery_K)\
**Post date:** [August 7, 2008, 5:12pm UTC](https://www.ruby-forum.com/t/upload-module-2-0-4/145220/8 "2008-08-07T17:12:57Z")

</div>

On 8/7/08, Valery K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I agree with you. The proper uploader should be able to handle partial  
> uploads. This would be a nice challenge for me to implement chunked  
> transfer encoding and byte ranges support for PUT.
> 
> May be I’ll consider this later.

PUT already can accept byte ranges more or less - the client just has  
to tell the script (PHP for example) something like  
put.php?offset=123456 - and then in php you fseek($fp, $offset) and  
resume filling in the content from there.

It takes a smart client to know where it left off though. That’s one  
thing I don’t know exactly how it works.

Here’s an example product:  
[http://www.radinks.com/upload/](http://www.radinks.com/upload/)  
[http://www.radinks.com/upload/plus/resume.php](http://www.radinks.com/upload/plus/resume.php) - their little marketing  
bit about upload resuming  
[http://www.radinks.com/upload/examples/resume.php.txt](http://www.radinks.com/upload/examples/resume.php.txt) - the PHP script  
they provide as an example
