# Upload module help

**URL:** <https://www.ruby-forum.com/t/upload-module-help/204847>\
**Category:** NGINX\
**Created:** [March 23, 2011, 8:18am UTC](https://www.ruby-forum.com/t/upload-module-help/204847 "2011-03-23T08:18:29Z")\
**Posts on this page:** 11\
**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:** [March 23, 2011, 8:18am UTC](https://www.ruby-forum.com/t/upload-module-help/204847/1 "2011-03-23T08:18:29Z")

</div>

hi,  
i am using nginx upload module to upload files.i am running this in  
ubuntu.when i upload files .its working fine .but name of the file is  
something different .this is not taking the upload \_set\_form\_field  
values. i dont know what went wrong.here is my conf file below

plz help me if u know

worker\_processes 20;

error\_log logs/error.log notice;

working\_directory /usr/local/nginx;

events {  
worker\_connections 1024;  
}

http {  
include mime.types;  
default\_type application/octet-stream;

```
server {
    listen 80;
    client_max_body_size 100m;

    # Upload form should be submitted to this location
    location /upload {
        # Pass altered request body to this location
        upload_pass @test;

        # Store files to this directory
        # The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8

```

9 should exist  
upload\_store /tmp 1;

```
        # Allow uploaded files to be read only by user
        upload_store_access user:r;

        # Set specified fields in request body
        upload_set_form_field "${upload_field_name}_name"

```

$upload\_file\_name;  
upload\_set\_form\_field “${upload\_field\_name}\_content\_type”  
$upload\_content\_type;  
upload\_set\_form\_field “${upload\_field\_name}\_path”  
$upload\_tmp\_path;

```
        # Inform backend about hash and size of a file
        upload_aggregate_form_field "${upload_field_name}_md5"

```

$upload\_file\_md5;  
upload\_aggregate\_form\_field “${upload\_field\_name}\_size”  
$upload\_file\_size;

```
        upload_pass_form_field "^submit$|^description$";
    }

    # Pass altered request body to a backend
    location @test {
        proxy_pass http://localhost:8080;
    }
}

```

server{  
listen 8080;  
}  
}

Posted at Nginx Forum:

> **[upload module help](https://forum.nginx.org/read.php?2,185057,185057#msg-185057)**
>
> hi, i am using nginx upload module to upload files.i am running this in ubuntu.when i upload files .its working fine .but name of the file is something different .this is not taking the upload \_set\_form\_field values. i dont know what went wrong.here...

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [March 23, 2011, 8:37am UTC](https://www.ruby-forum.com/t/upload-module-help/204847/2 "2011-03-23T08:37:16Z")

</div>

Hello,

you can try a small config like this:

```
 location /form {
     echo '<form action="/upload" enctype="multipart/form-data"

```

method=“post”\>’;  
echo ‘’;  
echo ‘’;  
echo ‘’;  
}

```
 location /upload {
     upload_pass /script-to-process;
     upload_store /var/tmp;
     upload_store_access user:r;
     upload_set_form_field $upload_field_name.name 

```

“$upload\_file\_name”;  
upload\_set\_form\_field $upload\_field\_name.path  
“$upload\_tmp\_path”;  
upload\_cleanup 400-505;  
}

in your process script you get

$\_POST[file\_path] # this is the file with “something different”  
$\_POST[file\_name] # this is your filename

Cheers,

Alexander

Am 23.03.2011 08:17, schrieb vetri:

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [March 23, 2011, 10:18am UTC](https://www.ruby-forum.com/t/upload-module-help/204847/3 "2011-03-23T10:18:03Z")

</div>

Mr Alexander ,

```
  i tried ur config but it is showing echo is a unknown

```

directive.what is the problem with echo in the config.

```
 can i use echo really in the config like that?

```

and thanks for the reply

Posted at Nginx Forum:

> **[Re: upload module help](https://forum.nginx.org/read.php?2,185057,185079#msg-185079)**
>
> hi, i am using nginx upload module to upload files.i am running this in ubuntu.when i upload files .its working fine .but name of the file is something different .this is not taking the upload \_set\_form\_field values. i dont know what went wrong.here...

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [March 23, 2011, 12:03pm UTC](https://www.ruby-forum.com/t/upload-module-help/204847/4 "2011-03-23T12:03:25Z")

</div>

Sorry, yes, echo is no build in option. But you can put this  
code into a simple html file. This code shoud only show the  
names for the formfields…

Am 23.03.2011 10:17, schrieb vetri:

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [March 24, 2011, 1:10pm UTC](https://www.ruby-forum.com/t/upload-module-help/204847/5 "2011-03-24T13:10:38Z")

</div>

mr alexander,

i am already using form to to upload files. my doubt is why its not  
saving the file in uploaded file name.it is saving the file in number  
form like this 0040353221 .i dont know why its happening and one more  
question how to parse header using nginx configuration ?

thanks for the reply

Posted at Nginx Forum:

> **[Re: upload module help](https://forum.nginx.org/read.php?2,185057,185375#msg-185375)**
>
> hi, i am using nginx upload module to upload files.i am running this in ubuntu.when i upload files .its working fine .but name of the file is something different .this is not taking the upload \_set\_form\_field values. i dont know what went wrong.here...

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [March 23, 2011, 10:24am UTC](https://www.ruby-forum.com/t/upload-module-help/204847/6 "2011-03-23T10:24:56Z")

</div>

On Wed, Mar 23, 2011 at 5:17 PM, vetri [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Mr Alexander ,
> 
> ```
> i tried ur config but it is showing echo is a unknown
> 
> ```
> 
> directive.what is the problem with echo in the config.

The echo directive is provided by the ngx\_echo module:

[GitHub - openresty/echo-nginx-module: An Nginx module for bringing the power of "echo", "sleep", "time" and more to Nginx's config file · GitHub](http://github.com/agentzh/echo-nginx-module)

It’s very handy in debugging nginx.conf stuffs 😉

Cheers,  
-agentzh

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [March 26, 2011, 10:08pm UTC](https://www.ruby-forum.com/t/upload-module-help/204847/7 "2011-03-26T22:08:20Z")

</div>

vetri wrote:

> mr alexander,
> 
> i am already using form to to upload files. my doubt is why its not  
> saving the file in uploaded file name.it is saving the file in number  
> form like this 0040353221 .

This is because it’s a temporary file. Saving an uploaded file under the  
original name is neither secure nor convenient.

Your script must take care of the permanent name for the file.

> i dont know why its happening and one more  
> question how to parse header using nginx configuration ?

–  
Best regards,  
Valery K.

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [March 28, 2011, 6:33am UTC](https://www.ruby-forum.com/t/upload-module-help/204847/8 "2011-03-28T06:33:37Z")

</div>

mr valery,  
thanks for the information and i have given the  
configuration above .could you tell me what went wrong.why its taking  
the file as temporary file and i need configuration help to save the  
file in real name.i need to know how to optimize the configuration

and thanks for the reply

Posted at Nginx Forum:

> **[Re: upload module help](https://forum.nginx.org/read.php?2,185057,186258#msg-186258)**
>
> hi, i am using nginx upload module to upload files.i am running this in ubuntu.when i upload files .its working fine .but name of the file is something different .this is not taking the upload \_set\_form\_field values. i dont know what went wrong.here...

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [March 28, 2011, 2:33pm UTC](https://www.ruby-forum.com/t/upload-module-help/204847/9 "2011-03-28T14:33:01Z")

</div>

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

> mr valery,  
> thanks for the information and i have given the  
> configuration above .could you tell me what went wrong.why its taking  
> the file as temporary file and i need configuration help to save the  
> file in real name.

It is up to you to implement a script that does this job. Upload module  
can save the content of the file fields only into temporary files.

> i need to know how to optimize the configuration

–  
Regards,  
Valery K.

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [March 29, 2011, 11:27am UTC](https://www.ruby-forum.com/t/upload-module-help/204847/10 "2011-03-29T11:27:10Z")

</div>

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

> mr valery,
> 
> is there any module to unzip ,checksum calculation for the uploaded  
> file?

Experimental version of upload module can unzip files:

> **[GitHub - vkholodkov/nginx-upload-module: A module for nginx web server for handling file...](https://github.com/vkholodkov/nginx-upload-module)**
>
> A module for nginx web server for handling file uploads using multipart/form-data encoding (RFC 1867).

Calculating CRC32 is possible with stable version.

–  
Regards,  
Valery K.

---

<div class="post-metadata">

**Author:** ![vetri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/3ab097/32.png) [@vetri](https://www.ruby-forum.com/u/vetri)\
**Post date:** [March 29, 2011, 6:58am UTC](https://www.ruby-forum.com/t/upload-module-help/204847/11 "2011-03-29T06:58:47Z")

</div>

mr valery,

is there any module to unzip ,checksum calculation for the uploaded  
file?

Posted at Nginx Forum:

> **[Re: upload module help](https://forum.nginx.org/read.php?2,185057,186511#msg-186511)**
>
> hi, i am using nginx upload module to upload files.i am running this in ubuntu.when i upload files .its working fine .but name of the file is something different .this is not taking the upload \_set\_form\_field values. i dont know what went wrong.here...
