# Extend the upload module

**URL:** <https://www.ruby-forum.com/t/extend-the-upload-module/219194>\
**Category:** NGINX\
**Created:** [April 23, 2012, 3:52pm UTC](https://www.ruby-forum.com/t/extend-the-upload-module/219194 "2012-04-23T15:52:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 23, 2012, 3:52pm UTC](https://www.ruby-forum.com/t/extend-the-upload-module/219194/1 "2012-04-23T15:52:24Z")

</div>

Hello

I am using the /nginx\_upload\_module-2.2.0 with nginx 1.0.15  
with great success

I would like to extend it in two ways:

(1)  
Each HTTP POST request to the module contains a username and a password  
field and I would like to make some checks on those values as early as  
possible and possibly reject the request even before the file is  
uploaded.

(2)  
I would like to save the file in a directory which depends on the file  
name and using the original file name instead of the current 10-digit  
000… filename

I have studied the code a little bit but I am still unclear as to where  
exactly I should look to implement (1) and (2)

thanks!

Posted at Nginx Forum:

> **[extend the upload module](https://forum.nginx.org/read.php?2,225666,225666#msg-225666)**
>
> Hello I am using the /nginx\_upload\_module-2.2.0 with nginx 1.0.15 with great success I would like to extend it in two ways: (1) Each HTTP POST request to the module contains a username and a password field and I would like to make some check

---

<div class="post-metadata">

**Author:** ![JCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@JCR](https://www.ruby-forum.com/u/JCR)\
**Post date:** [April 23, 2012, 8:12pm UTC](https://www.ruby-forum.com/t/extend-the-upload-module/219194/2 "2012-04-23T20:12:59Z")

</div>

On Mon, Apr 23, 2012 at 09:52:04AM -0400, JCR wrote:

Hi there,

> I am using the /nginx\_upload\_module-2.2.0 with nginx 1.0.15  
> with great success
> 
> I would like to extend it in two ways:

I suspect that these extensions would be out of scope for this module,  
which seems to be more about making it easier to write your own form  
handler.

That said, I’m sure no-one’s going to stop you from coding.

> (1)  
> Each HTTP POST request to the module contains a username and a password  
> field and I would like to make some checks on those values as early as  
> possible and possibly reject the request even before the file is  
> uploaded.

If you used http basic authentication, the effect of this could come  
for free. But you don’t.

Fundamentally, what you seem to want is for the handler to read a part  
of the POST request body and then decide whether to respond and close  
the connection, or accept the rest of the request body.

I’m not sure how you’d go about that.

> (2)  
> I would like to save the file in a directory which depends on the file  
> name and using the original file name instead of the current 10-digit  
> 000… filename

That one is probably better handled in your own form handler – you can  
be given the original suggested filename and the 10-digit filename, and  
do a “mv” of one to the other, handling duplicates and evil filenames as  
you see fit. No need to hard-code the handling within the module.

You probably will want to make sure that “upload\_store” is on the same  
filesystem as you wish the files to end up on.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![JCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@JCR](https://www.ruby-forum.com/u/JCR)\
**Post date:** [April 23, 2012, 8:40pm UTC](https://www.ruby-forum.com/t/extend-the-upload-module/219194/3 "2012-04-23T20:40:59Z")

</div>

> I suspect that these extensions would be out of scope for this module,  
> which seems to be more about making it easier to write your own form  
> handler.

> Fundamentally, what you seem to want is for the handler to read a part  
> of the POST request body and then decide whether to respond and close  
> the connection, or accept the rest of the request body.
> 
> I’m not sure how you’d go about that.

This is what nginx-perl is for.
