Using http_upload_module with http_perl_module
erd
nginx-forum at nginx.us
Mon Jul 9 08:25:25 UTC 2012
Hi, everyone.
I am trying to implement upload using http_upload_module with
http_perl_module. But I am stuck at moment when upload_module should
send obtained information about successfuly uploaded file to the
internal redirect @upload. @upload location perl handler invoke, but it
never recieved any of arguments, even those, which defined from
upload_pass_form_field.
I mean, I have received temporary files at "/u" location, and I have
seen WebLab::upl handler result, but without any POST arguments inside.
I probably doing something wrong, but I do not know what. And sorry for
my English.
nginx version: nginx/1.3.2
configure arguments: --prefix=/usr/local/etc/nginx --with-cc-opt='-I
/usr/local/include' --with-ld-opt='-L /usr/local/lib'
--conf-path=/usr/local/etc/nginx/nginx.conf
--sbin-path=/usr/local/sbin/nginx --pid-path=/var/run/nginx.pid
--error-log-path=/var/log/nginx-error.log --user=www --group=www
--with-file-aio --with-ipv6
--http-client-body-temp-path=/var/tmp/nginx/client_body_temp
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi_temp
--http-proxy-temp-path=/var/tmp/nginx/proxy_temp
--http-scgi-temp-path=/var/tmp/nginx/scgi_temp
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi_temp
--http-log-path=/var/log/nginx-access.log
--add-module=/usr/ports/www/nginx-devel/work/ngx_cache_purge-1.6
--with-http_image_filter_module --with-http_perl_module
--with-http_stub_status_module --with-http_sub_module
--add-module=/usr/ports/www/nginx-devel/work/nginx_upload_module-2.2.0
--add-module=/usr/ports/www/nginx-devel/work/masterzen-nginx-upload-progress-module-a788dea
--add-module=/usr/ports/www/nginx-devel/work/chaoslawful-lua-nginx-module-3b1e9aa
--with-pcre
--add-module=/usr/ports/www/nginx-devel/work/simpl-ngx_devel_kit-bc97eea
--add-module=/usr/ports/www/nginx-devel/work/calio-iconv-nginx-module-abdac17
#nginx config
server {
client_header_buffer_size 4k;
...
location /u {
root /home/webl/www/node1;
error_page 403 = 404;
}
location @upload {
perl WebLab::upl;
}
location =/upload {
client_max_body_size 15m;
upload_pass @upload;
upload_store /home/webl/www/node1/u;
upload_store_access user:r;
# 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_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 "^test$";
upload_cleanup 400-404 499 500-505;
}
}
#WebLab::upl handler
package WebLab;
sub upl
{
no strict;
no warnings;
shift->has_request_body(sub{
my $r = shift;
$r->send_http_header("text/plain");
$r->print("request_body: \"", $r->request_body, "\"\n");
$r->print("request_body_file: \"", $r->request_body_file, "\"\n");
});
}
#request to /upload
POST /upload HTTP/1.1
Host: node1.webl
Connection: keep-alive
...
Content-Type: multipart/form-data;
boundary=----WebKitFormBoundaryJ0GtAjmfwCLxtzFL
------WebKitFormBoundaryJ0GtAjmfwCLxtzFL
Content-Disposition: form-data; name="file"; filename="image.jpg"
Content-Type: image/jpeg
------WebKitFormBoundaryJ0GtAjmfwCLxtzFL
Content-Disposition: form-data; name="test"
val
------WebKitFormBoundaryJ0GtAjmfwCLxtzFL--
#server response (from @upload)
request_body: "------WebKitFormBoundaryJ0GtAjmfwCLxtzFL"
request_body_file: ""
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,228424,228424#msg-228424
More information about the nginx
mailing list