Forward arguments in upload module

hi all,

uploading files via nginx is awesome .i am sending query arguments

in post operation which will be passed to backend server.i want to
append one more key value pair to that query arguments to send into
backend server(own key value will be taken from program).if i want to do
like this which part of the program i should concentrate to append my
own arguments to that query arguments and send to backend server.if
someone has code knowledge just help me where to concentrate and help me
do this possible

Thanks in Advance

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,205669,205669#msg-205669

Hello Vetri,

add your argument to:

upload_pass_form_field

Cheers,

Alexander

mr kunz,

Thanks for the reply . i am not using form to upload files. i am using
java client to send files to nginx via post operation.

even though i tried what u said there is no notification at the backend
.here is the config

worker_processes 20;

error_log /home/vetriselvanm/Desktop/upload/error.log info;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

server {
    listen       8085;
    client_max_body_size 0;



    # Upload form should be submitted to this location
     location /zsupload {
        # 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 /home/vetriselvanm/Desktop/upload;

        # Allow uploaded files to be read only by user
        upload_store_access user:rw group:rw all:rw;

        # 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:8090;

    }

}

}
in that port 8090 one server is running to get notification and it will
get key value and it will print it.

what do i do?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,205669,205829#msg-205829

On Sat, Jun 11, 2011 at 12:40:36AM -0400, vetri wrote:

Hi there,

i am sending query arguments in post operation which will be passed
to backend server.

Thanks for the reply . i am not using form to upload files. i am using
java client to send files to nginx via post operation.

So your java client is doing roughly the same thing as

curl -v -F [email protected] -F submit=on -F k=v
http://localhost:8085/zsupload

where “k=v” is your query arguments. Is that correct?

If you test using that tool, you’ll be able to get the nginx config
right first; then you can change the client as needed to make sure it
fits.

i want to append one more key value pair to that query
arguments to send into backend server(own key value will be taken from
program)

If you want your program to send the extra k1=v1, then you just do it
the same way as you set the original k=v – one more “-F k1=v1” in the
curl command line, and whatever you did in your java client for the
live solution.

If you want nginx to create the extra k1=v1 in between getting from the
client and sending to the backend, then you configure it as was
suggested.

See below.

even though i tried what u said there is no notification at the backend
.here is the config

        # 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”;

Here, adding

upload_set_form_field k1 v1;

will add that key/value pair to the request sent to the backend. You
can replace either of the k1/v1 strings with nginx variables that have
been set, just like the three previous lines.

That is for “nginx creates the extra k1/v1”.

        upload_pass_form_field "^submit$|^description$";

That setting is a regex which determines which of the keys sent by the
original client will be copied into the request sent to the backend.

So if you want the client to send k1/v1 and have it sent to the backend,
then you’ll have to modify the above line to include matching “k1”.

Good luck,

f

Francis D. [email protected]

On Mon, Jun 13, 2011 at 02:12:12AM -0400, vetri wrote:

Hi there,

     i am sending my key=value through

http://localhost:8085/zsupload?filename=run.txt&content-type=txt&checksum=“6454456456”

It is possible to POST to a url with a query string, but it is
unusual. And I believe that the upload module doesn’t automatically
process the query string for you.

The right thing for you to do is probably to send all of these key-value
pairs within the body of the POST request, and just let the upload
module
do what it is good at.

by turning upload_pass_args on,i could not notify the path which is
/home/vetriselvanm/Desktop/upload/0000000001 to backend and that is the
path where file is stored. but i used that upload_set_form_field what u
specified above didnt work .i could not recieve the notification at

If you really want to POST with a query string, then you’ll want
something like

upload_set_form_field filename $arg_filename;

in the nginx config.

Note that this will cause nginx to send the key-value pair in the body
of the POST request it makes to the backend, not in the query string.

backend.if i want to send the
path=/home/vetriselvanm/Desktop/upload/0000000001 to the backend how
could i use this paerfectly or do have to enable any other module?

You don’t need any module at all, you just need a working form handler
as the backend.

But it is useful to use the upload module, to make the backend form
handler simpler.

Good luck with it,

f

Francis D. [email protected]

mr francis,

     i am sending my key=value through

http://localhost:8085/zsupload?filename=run.txt&content-type=txt&checksum=“6454456456”
by turning upload_pass_args on,i could not notify the path which is
/home/vetriselvanm/Desktop/upload/0000000001 to backend and that is the
path where file is stored. but i used that upload_set_form_field what u
specified above didnt work .i could not recieve the notification at
backend.if i want to send the
path=/home/vetriselvanm/Desktop/upload/0000000001 to the backend how
could i use this paerfectly or do have to enable any other module?

Thanks for the Reply

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,205669,206331#msg-206331

mr francis,

sorry for asking again. i have to make clear. i sent the file via form
in browser.now i tried in browser .u have specified

upload_set_form_field above . i used that

        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”;

In the Server log i printed Field name and value .here what i got
when i upload nginx.tar.gz

Field Name is      file1.name                      Field Value is

nginx.tar.gz

Field Name is      file1.content_type          Field Value is

application/x-zip

Field Name is       file1.path                         Field value

is /home/vetriselvanm/Desktop/upload/0000000001

Now i have got the three key value pair for the file specified
above.

My backend server will parse the key value pair and it will print it.
for example if it recieves name=run.txt

it will print paramname ::name and paramvalue::run.txt

after the file is uploded i am receiving notification but no
key=value is passed to backend .

i used upload_pass_form_field directive to pass key=value to backend
.below is the directive what i used .

upload_pass_form_field “^submit$|^description$”;

am i using the regex pattern correctly?or should i change it ,if i have
to change? how ? give me backend handler code to parse key=value or
getting the above key values which is working for u?

Thanks for the Reply

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,205669,206640#msg-206640

On Tue, Jun 14, 2011 at 02:07:35AM -0400, vetri wrote:

Hi there,

it looks like your backend is still unclear about the difference between
POST data and query strings. This is not nginx-related, but more like
CGI programming (or writing a form handler).

is /home/vetriselvanm/Desktop/upload/0000000001
This means your backend will be getting the same key/value pairs.

My backend server will parse the key value pair and it will print it.
for example if it recieves name=run.txt

it will print paramname ::name and paramvalue::run.txt

after the file is uploded i am receiving notification but no
key=value is passed to backend .

The key/value pair is passed to the backend. It is not passed like
key=value in the query string; it is instead passed like

------------------------------8c04206dfc20
Content-Disposition: form-data; name=“key”

value
------------------------------8c04206dfc20

within the POST body.

For each

upload_set_form_field key value;

you include in the nginx config, you will get one block like that.

i used upload_pass_form_field directive to pass key=value to backend
.below is the directive what i used .

upload_pass_form_field “^submit$|^description$”;

If the original POST included fields with names that match that regex
– in this case, exactly “submit” or “description” – in the POST body,
then they will be sent though to the backend.

am i using the regex pattern correctly?or should i change it ,if i have
to change? how ? give me backend handler code to parse key=value or
getting the above key values which is working for u?

Use the following 10 lines as a test CGI script (running on a web server
which runs CGI, so not nginx) to see exactly what is sent.

===
#!/bin/sh

echo Content-Type: text/plain
echo
env
echo ===
[ “$REQUEST_METHOD” = POST ] &&
[ -n “$CONTENT_LENGTH” ] &&
dd ibs=1 count=$CONTENT_LENGTH
echo ===

Post to that directly (with a small, text-only file, for simplicity);
and post to that as the “upload_pass” in the nginx config. You will see
exactly what is received each time, and you will see what changes the
upload module makes.

And then you can adjust your backend code to match.

Good luck with it,

f

Francis D. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs