# Upload module fails in some cases

**URL:** <https://www.ruby-forum.com/t/upload-module-fails-in-some-cases/219182>\
**Category:** NGINX\
**Created:** [April 23, 2012, 4:26am UTC](https://www.ruby-forum.com/t/upload-module-fails-in-some-cases/219182 "2012-04-23T04:26:27Z")\
**Posts on this page:** 3\
**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:** [April 23, 2012, 4:26am UTC](https://www.ruby-forum.com/t/upload-module-fails-in-some-cases/219182/1 "2012-04-23T04:26:27Z")

</div>

Hello,

I and using nginx 1.0.15 with the third-party module  
nginx\_upload\_module-2.2.0/

When I am using an html form all works perfectly and I can see the  
uploaded files and the post values as expected.

But, when I send the HTTP Post request from a Poco application, it does  
not work. ([pocoproject.org](http://pocoproject.org))

I am pasting below the code of that C++ Poco app. I don’t think that you  
need to be an expert at Poco to understand it.

114 std::ostringstream content;  
115 content \<\< “------WebKitFormBoundaryq2BIJhJChD7qIY1W\r\n”;  
116 content \<\< “Content-Disposition: form-data;  
name="submit"\r\n\r\n”  
117 “Upload\r\n”  
118 “------WebKitFormBoundaryq2BIJhJChD7qIY1W\r\n”;  
119 content \<\< “Content-Disposition: form-data; name="file";  
filename="test.txt"\r\n\r\n”  
120 “Content-Type: text/plain\r\n”  
121 “This is a test.\r\n”  
122 “------WebKitFormBoundaryq2BIJhJChD7qIY1W–”;  
123  
124 std::ostringstream os;  
125 os \<\< “POST /upload HTTP/1.0\r\n”  
126 “Host: ip:31000\r\n”  
127 “User-Agent: AAA\r\n”  
128 “Accept:  
text/plain,application/xhtml+xml,application/xml;q=0.9,_/_;q=0.8\r\n”  
129 “Accept-Language:  
en-us,ko;q=0.9,ja;q=0.7,cs;q=0.6,th;q=0.4,zh;q=0.3,en;q=0.1\r\n”  
130 “Accept-Encoding: gzip,deflate\r\n”  
131 “Accept-Charset: ISO-8859-1,utf-8;q=0.7,\*;q=0.7\r\n”  
132 “Referer: ip\r\n”  
133 “Content-Type: multipart/form-data;  
boundary=------WebKitFormBoundaryq2BIJhJChD7qIY1W\r\n”;  
134  
135 os \<\< "Content-Length: " \<\< strlen(content.str().c\_str()) \<\<  
“\r\n\r\n”;  
136 os \<\< content.str();  
137  
138 Poco::Net::SocketAddress sa(“ip”, 31000);  
139 Poco::Net::StreamSocket socket(sa);  
140 Poco::Net::SocketStream str(socket);  
141 str \<\< os.str();  
142 str.flush();  
143 Poco::StreamCopier::copyStream(str, std::cout);  
144 return;

I am getting this from the server  
HTTP/1.1 200 OK  
Server: nginx/1.0.15  
Date: Mon, 23 Apr 2012 02:00:45 GMT  
Content-Type: text/html  
Connection: close  
X-Powered-By: PHP/5.1.6  
Content-Length: 98

POST  
Array  
(  
[\<ngx\_upload\_module\_dummy\>] =\>  
)  
  
FILES  
Array  
(  
)

Drilling into  
nginx\_upload\_module-2.2.0/ngx\_http\_upload\_module.c  
It seems that the problem is inside the function  
static ngx\_int\_t upload\_process\_buf(ngx\_http\_upload\_ctx\_t \*upload\_ctx,  
u\_char \*start, u\_char \*end)  
and more precisely, it appears that from the html from the scope below  
is entered while from the poco app it is never entered

3509 if(upload\_ctx-\>boundary\_pos == upload\_ctx-\>boundary.data +  
upload\_ctx-\>boundary.len)  
3510 {  
3512 upload\_ctx-\>state = upload\_state\_after\_boundary;  
3513 upload\_ctx-\>boundary\_start = upload\_ctx-\>boundary.data;  
3514 upload\_ctx-\>boundary\_pos = upload\_ctx-\>boundary\_start;  
3515 }

maybe my header is wrong… I am running out of ideas to make this work

I am pasting below the config file:  
1 #user nobody;  
2 worker\_processes 1;  
3 #error\_log logs/error.log;  
4 error\_log logs/debug.log debug;  
5 #error\_log logs/error.log info;  
6 #pid logs/nginx.pid;  
7 events {  
8 worker\_connections 1024;  
9 }  
10 http {  
11  
12 proxy\_buffering on;  
13 proxy\_buffer\_size 8k;  
14 proxy\_buffers 2048 8k;  
15  
16 include mime.types;  
17 default\_type application/octet-stream;  
18 log\_format main '$request\_body $remote\_addr - $remote\_user  
[$time\_local] “$request” ’  
19 '$status $body\_bytes\_sent “$http\_referer” ’  
20 ‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;  
21 access\_log logs/access.log main;  
22 sendfile on;  
23 server\_names\_hash\_max\_size 1024;  
24 server\_names\_hash\_bucket\_size 128;  
25 client\_body\_temp\_path /usr/local/nginx/uploads;  
26 keepalive\_timeout 65;  
27  
28 chunkin on;  
29  
30 server {  
31 client\_max\_body\_size 100m;  
32 listen ip:31000;  
33  
34 #location /upload.php {  
35 #location ~ .php$ {  
36  
37 error\_page 411 = @my\_error;  
38 location @my\_error {  
39 chunkin\_resume;  
40 }  
41 location /upload{  
42  
43 chunkin\_resume;  
44  
45 # Pass altered request body to this location  
46 upload\_pass @uploadfiles;  
47 upload\_store /usr/local/nginx/uploads;  
48 #upload\_store\_access user:r;  
49 # Set specified fields in request body  
50 upload\_set\_form\_field $upload\_field\_name.name  
“$upload\_file\_name”;  
51 upload\_set\_form\_field $upload\_field\_name.content\_type  
“$upload\_content\_type”;  
52 upload\_set\_form\_field $upload\_field\_name.path  
“$upload\_tmp\_path”;  
53 # Inform backend about hash and size of a file  
54 #upload\_aggregate\_form\_field “$upload\_field\_name.md5”  
“$upload\_file\_md5”;  
55 upload\_aggregate\_form\_field “$upload\_field\_name.size”  
“$upload\_file\_size”;  
56 upload\_pass\_form\_field “^username$|^password$”;  
57 #upload\_pass\_form\_field “.\*”;  
58 upload\_cleanup 400 404 499 500-505;  
59 upload\_pass\_args on;  
60 upload\_max\_part\_header\_len 100m;  
61 upload\_max\_output\_body\_len 0;  
62 }  
63 location ~ .php$ {  
64 proxy\_pass [http://127.0.0.1:80](http://127.0.0.1:80);  
65 }  
66 location = /favicon.ico {  
67 access\_log off;  
68 log\_not\_found off;  
69 }  
70 location /hello{  
71 hello;  
72 }  
73 location @uploadfiles{  
74 rewrite ^ /upload.php last;  
75 #proxy\_pass[http://127.0.0.1:80](http://127.0.0.1:80);  
76 }  
77 location = /boom{  
78 }  
79 #location / {  
80 # root html;  
81 # index index.html index.htm;  
82 #}  
83 error\_page 500 502 503 504 /50x.html;  
84 #location = /50x.html {  
85 # root html;  
86 #}  
87 }  
88 }

Note that if I disable the module  
'–add-module=/root/nginx/agentzh-chunkin-nginx-module-ddc0dd5", the  
issue remains

Thanks in advance for any idea

Posted at Nginx Forum:

> **[upload module fails in some cases](https://forum.nginx.org/read.php?2,225636,225636#msg-225636)**
>
> Hello, I and using nginx 1.0.15 with the third-party module nginx\_upload\_module-2.2.0/ When I am using an html form all works perfectly and I can see the uploaded files and the post values as expected. But, when I send the HTTP Post request from a...

---

<div class="post-metadata">

**Author:** ![JCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@JCR](https://www.ruby-forum.com/u/JCR)\
**Post date:** [April 23, 2012, 8:47am UTC](https://www.ruby-forum.com/t/upload-module-fails-in-some-cases/219182/2 "2012-04-23T08:47:53Z")

</div>

Hello!

On Sun, Apr 22, 2012 at 10:25:16PM -0400, JCR wrote:

> 119 content \<\< “Content-Disposition: form-data; name="file";  
> filename="test.txt"\r\n\r\n”  
> 120 “Content-Type: text/plain\r\n”  
> 121 “This is a test.\r\n”  
> 122 “------WebKitFormBoundaryq2BIJhJChD7qIY1W–”;

4 dashes in the boundary here (following the ‘“–” boundary’  
syntax as per RFC 2046).

> 131 “Accept-Charset: ISO-8859-1,utf-8;q=0.7,\*;q=0.7\r\n”  
> 132 “Referer: ip\r\n”  
> 133 “Content-Type: multipart/form-data;  
> boundary=------WebKitFormBoundaryq2BIJhJChD7qIY1W\r\n”;

And 6 dashes here. This is unlikely to work.

Maxim D.

---

<div class="post-metadata">

**Author:** ![JCR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@JCR](https://www.ruby-forum.com/u/JCR)\
**Post date:** [April 23, 2012, 2:47pm UTC](https://www.ruby-forum.com/t/upload-module-fails-in-some-cases/219182/3 "2012-04-23T14:47:35Z")

</div>

Hello Maxim

Thanks a lot! I went back to RFC 2046 and understood clearly my mistake

Posted at Nginx Forum:

> **[Re: upload module fails in some cases](https://forum.nginx.org/read.php?2,225636,225657#msg-225657)**
>
> Hello, I and using nginx 1.0.15 with the third-party module nginx\_upload\_module-2.2.0/ When I am using an html form all works perfectly and I can see the uploaded files and the post values as expected. But, when I send the HTTP Post request from a...
