Welcome! Log In Create A New Profile

Advanced

problem with upload multimedia files by nginx

Posted by plesken 
problem with upload multimedia files by nginx
March 25, 2010 06:16AM
I'm new user on this forum. I'm using nginx a lot of time and I didn't have problem with it.
The problem was begun when I wanted to upload files by my simple php form to server.
I observed that nginx didn't upload multimedia files (flv, mp3), that's why I reconfigured nginx whith "upload module" and "progress module".

1. Could you tell me why "clear" nginx (default debian installer) didn't work correctly?

I reconfigured my nginx:

location /upload {
upload_pass /upl;
upload_pass_args on;
upload_store /tmp;
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_set_form_field $upload_field_name.tmp $upload_tmp_path;
upload_aggregate_form_field $upload_field_name.tmp "$upload_tmp_path";
upload_aggregate_form_field $upload_field_name.content_type "$upload_content_type";
upload_pass_form_field "^submit$|^description$";
}

location /upl {
include /etc/nginx/fastcgi_params;
keepalive_timeout 0;
fastcgi_param SCRIPT_FILENAME /var/www/hobbyy$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param REQUEST_METHOD $request_method;
proxy_set_header Host $http_host;
proxy_pass https://hobbyy.com/data/upload;
}

and upload works fine, but I can't get information about tmp file name, content type etc.

2. How can I get this information by php script?

Best regards

Plesken
Re: problem with upload multimedia files by nginx
March 29, 2010 03:53AM
I have a similar problem, when using nginx-0.7.65, nginx_upload_module-2.0.12 and the embedded perl module, the uploaded files get processed properly, and, using proxy_pass, a properly changed request body is passed (I used proxy_pass http://localhost:1111 / nc -lvv 1111):

[code]POST /upload HTTP/1.0
Host: localhost:1111
[...]
Content-Type: multipart/form-data; boundary=---------------------------9357852613357
Content-Length: 503

-----------------------------9357852613357
Content-Disposition: form-data; name="upload.name"

test.txt
-----------------------------9357852613357
Content-Disposition: form-data; name="upload.path"

/tmp/0063992968
-----------------------------9357852613357
Content-Disposition: form-data; name="upload.crc32"

da59d0b0
-----------------------------9357852613357
Content-Disposition: form-data; name="upload.size"

67
-----------------------------9357852613357--[/code]

But when I use my perl module, the request_body is cut-off to a one-liner:

[code]req='-----------------------------9357852613357'[/code]

Is it just me not knowing a way to read a buffered request_body, or is there actually something wrong with this setup/modules?

[code][hr]nginx.conf[hr]
perl_require 'test.pm';

location /upload {
upload_max_file_size 5m;
upload_pass /test;

upload_store '/tmp';
upload_store_access user:rw;

upload_set_form_field $upload_field_name.name "$upload_file_name";
upload_set_form_field $upload_field_name.path "$upload_tmp_path";
upload_aggregate_form_field "$upload_field_name.crc32" "$upload_file_crc32";
upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";

upload_cleanup 400 404 500-505;
}

location /test {
client_body_in_file_only on;
client_body_in_single_buffer on;
perl test::handle;
}

[hr]test.pm[hr]

package test;
use nginx;

sub handle {
$req = shift;
$req->send_http_header('text/html');
$req->print("req='",$req->request_body,"'");
return OK;
}[/code]
Re: problem with upload multimedia files by nginx
March 29, 2010 04:57AM
And I actually used has_request_body, getting the same output (req='-----------------------------9357852613357'):

[code]sub procdata {
$req = shift;
$body = $req->request_body;
$req->send_http_header('text/html');
$req->print("req='",$body,"'");
return OK;
}

sub handle {
$req = shift;
return DECLINED unless ($req->request_method eq 'POST');
return 400 unless $req->has_request_body(\&procdata);
return OK;
}[/code]

Just uploading a file to /upload directly gave expected results. Also, here's a part of the debug log, when the last buffer is being written (notice the Resource temporarily unavailable and Connection reset by peer messages):

[code]2010/03/29 11:45:21 [debug] 31141#0: *1 http chunk: 0
2010/03/29 11:45:21 [debug] 31141#0: *1 write old buf t:1 f:0 0000000000687690, pos 0000000000687690, size: 155 file: 0, size: 0
2010/03/29 11:45:21 [debug] 31141#0: *1 write old buf t:1 f:0 0000000000000000, pos 0000000000687880, size: 4 file: 0, size: 0
2010/03/29 11:45:21 [debug] 31141#0: *1 write old buf t:1 f:0 0000000000687790, pos 0000000000687790, size: 48 file: 0, size: 0
2010/03/29 11:45:21 [debug] 31141#0: *1 write old buf t:0 f:0 0000000000000000, pos 000000000045F212, size: 2 file: 0, size: 0
2010/03/29 11:45:21 [debug] 31141#0: *1 write new buf t:0 f:0 0000000000000000, pos 000000000045E10A, size: 5 file: 0, size: 0
2010/03/29 11:45:21 [debug] 31141#0: *1 http write filter: l:1 f:0 s:214
2010/03/29 11:45:21 [debug] 31141#0: *1 http write filter limit 0
2010/03/29 11:45:21 [debug] 31141#0: *1 writev: 214
2010/03/29 11:45:21 [debug] 31141#0: *1 http write filter 0000000000000000
2010/03/29 11:45:21 [debug] 31141#0: *1 copy filter: 0 "/upload?"
2010/03/29 11:45:21 [debug] 31141#0: *1 http finalize request: 0, "/upload?" 1
2010/03/29 11:45:21 [debug] 31141#0: *1 event timer add: 3: 5000:1269852326897
2010/03/29 11:45:21 [debug] 31141#0: *1 http lingering close handler
2010/03/29 11:45:21 [debug] 31141#0: *1 recv: fd:3 -1 of 4096 2010/03/29 11:45:21 [debug] 31141#0: *1 recv() not ready (11: Resource temporarily unavailable) 2010/03/29 11:45:21 [debug] 31141#0: *1 lingering read: -2
2010/03/29 11:45:21 [debug] 31141#0: *1 event timer: 3, old: 1269852326897, new: 1269852326897
2010/03/29 11:45:21 [debug] 31141#0: *1 call_sv: 0 2010/03/29 11:45:21 [debug] 31141#0: *1 perl handler done: 0
2010/03/29 11:45:21 [debug] 31141#0: timer delta: 1
2010/03/29 11:45:21 [debug] 31141#0: posted events 0000000000000000
2010/03/29 11:45:21 [debug] 31141#0: worker cycle
2010/03/29 11:45:21 [debug] 31141#0: epoll timer: 5000
2010/03/29 11:45:21 [debug] 31141#0: epoll: fd:3 ev:0019 d:00007F82719C0170
2010/03/29 11:45:21 [debug] 31141#0: epoll_wait() error on fd:3 ev:0019
2010/03/29 11:45:21 [debug] 31141#0: *1 http lingering close handler
2010/03/29 11:45:21 [debug] 31141#0: *1 recv: fd:3 -1 of 4096
2010/03/29 11:45:21 [info] 31141#0: *1 recv() failed (104: Connection reset by peer), client: 62.XX.YYY.ZZ, server: yyy.com, request: "POST /upload HTTP/1.1", host: "...", referrer: "..."
2010/03/29 11:45:21 [debug] 31141#0: *1 lingering read: -1
2010/03/29 11:45:21 [debug] 31141#0: *1 http close request
2010/03/29 11:45:21 [debug] 31141#0: *1 http log handler
2010/03/29 11:45:21 [debug] 31141#0: *1 run cleanup: 00000000007DF7B0
2010/03/29 11:45:21 [debug] 31141#0: *1 free: 0000000000730FF0
2010/03/29 11:45:21 [debug] 31141#0: *1 free: 00000000007DE7F0, unused: 5
2010/03/29 11:45:21 [debug] 31141#0: *1 free: 0000000000686CD0, unused: 656
2010/03/29 11:45:21 [debug] 31141#0: *1 close http connection: 3
2010/03/29 11:45:21 [debug] 31141#0: *1 event timer del: 3: 1269852326897
2010/03/29 11:45:21 [debug] 31141#0: *1 free: 0000000000680810
2010/03/29 11:45:21 [debug] 31141#0: *1 free: 0000000000730580
2010/03/29 11:45:21 [debug] 31141#0: *1 free: 00000000006A00E0, unused: 8
2010/03/29 11:45:21 [debug] 31141#0: *1 free: 00000000006A01F0, unused: 128
2010/03/29 11:45:21 [debug] 31141#0: timer delta: 53
2010/03/29 11:45:21 [debug] 31141#0: posted events 0000000000000000
2010/03/29 11:45:21 [debug] 31141#0: worker cycle
2010/03/29 11:45:21 [debug] 31141#0: epoll timer: -1[/code]
Re: problem with upload multimedia files by nginx
April 02, 2010 01:46PM
Didn't anyone try to fuse the Embedded Perl Module with the Uploader Module?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 273
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready