Nginx and uploads

Hello,

I am trying to upload files to Nginx and process them via itself.
I have compiled it with nginx_upload_module-2.2.0.

My config is the following:
server {
listen 80;
server_name example.com;
client_max_body_size 100m;

location / {
    root   /www;
    autoindex on;
}
 location /upload {
    root    /www;

    if ($request_method = POST) {
    upload_pass @test;
    break;
}
    upload_store /www/upload;
    upload_store_access user:rw group:rw all:rw;
    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”;
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$”;
upload_cleanup 400 404 499 500-505;
}

location @test {
proxy_pass http://example.com:8080;
}

}

  server {
    listen       8080;
    server_name  example.com;
    location / {
    root   /www;
  }

}

This works, but it saves my uploads with random number names like
0000000001
0000000002 0000000003 0000000004 0000000005 0000000006 0000000007
0045422062 0059512315.
I want to save them with the original name.
Remember, my @test backend is also Nginx and not something else.

Pls help.

Posted at Nginx Forum:

I’m not sure you can really do what you want to. The upload module was
not
designed for this purpose. If you want to do this you either need to
modify
the source of the upload module or perhaps you can handle such logic by
using the lua module to script what to do with the file uploads.

Posted at Nginx Forum:

This seems odd. If it wasn’t meant for Nginx to process uploaded files,
then
it couldn’t have processed them by itself.
For example, I changed
location @test {
proxy_pass http://example.com:8080;

to
location @test {
default_type text/html;
root /www;
and removed the :8080 server part and it still works.
So I am inclined to think that there must be a way to set the filename
without going to such lenghts as to change the code.

Posted at Nginx Forum:

w00t Wrote:

and removed the :8080 server part and it still works.
So I am inclined to think that there must be a way to set the filename
without going to such lenghts as to change the code.

Yes there is, but the default nginx install does not have the features
available to do what you want and the upload module does not introduce
any
such feature either. If you want nginx to be able to rename files based
on
user input then you need a module which introduces that capability into
nginx.

Of course, at this point I’m talking theory only as I haven’t ever done
anything like this, but it should work provided either lua module or
perl
module has the adds the required features - in theory.

Posted at Nginx Forum:

On Tuesday 28 August 2012 19:02:31 w00t wrote:

This seems odd. If it wasn’t meant for Nginx to process uploaded files,
then it couldn’t have processed them by itself.

You should do this task in your application and it’s not odd (see below
why).

[…]

So I am inclined to think that there must be a way to set the filename
without going to such lenghts as to change the code.

Just rename the uploaded file is not enough. You also need to validate
its
content. Otherwise, you will open a potential security hole in your
server.

wbr, Valentin V. Bartenev

Indeed, after some more search I have found what you are saying.

Posted at Nginx Forum:

Hello!

On Tue, Aug 28, 2012 at 6:43 AM, Ensiferous [email protected]
wrote:

I’m not sure you can really do what you want to. The upload module was not
designed for this purpose. If you want to do this you either need to modify
the source of the upload module or perhaps you can handle such logic by
using the lua module to script what to do with the file uploads.

Yes! There’s a lua-resty-upload library for ngx_lua that can do
non-buffered uploading:

https://github.com/agentzh/lua-resty-upload

You don’t have to touch the disk at all if you prefer sending the data
chunks to the TCP/UDP backends (via cosockets) in a strict
non-buffered mode.

Best regards,
-agentzh