simple module question

Valery Kholodkov valery+nginxen at grid.net.ru
Sat Jul 12 02:33:43 MSD 2008


Manlio Perillo wrote:
> Valery Kholodkov ha scritto:
>> Hi!
>>
>> In my patch for processing uploads you can find an API to process 
>> multipart/form-data bodies:
>>
>> http://www.grid.net.ru/nginx/nginx-upload-patch.html
>>
>> What you need are files upload.c and upload.h.
>>
> 
> Thanks!
> 
>> I'm actually working now on the next version of this module which will 
>> be able to cut out and store uploaded files in temporal directory and 
>> proxy the remaining part of the body to a backend with brief 
>> information about files uploaded.
>>
> 
> My idea is to:
> 1) Modify the content-type from multipart/form-data to
>    application/x-www-form-urlencoded
> 2) Any non file parts are urlencoded and written to the new body
> 3) Files are written to temporary files, and in the new body is written:
>    name.filename=filename&name.path=path&name.content-type=content-type
>    where name is the field name and path is the temporary path used to
>    store the file.
> 
> With this method an application needs only to care about urlencoded 
> request body.

The problem with application/x-www-form-urlencoded is that it is 
percent-encoded and multipart/form-data is not, thus requiring us to 
deal with encoding, etc. Dealing with encodings is generally a bad idea 
and I prefer to think about request body as a stream of bytes.

Another problem is that if we rename attributes to name.filename= and 
name.path= this will require modifying existing applications and such 
thing would be quite unuseful.

Therefore what I do now is transferring almost identical request body to 
the backend with file fields converted to normal fields containing 
following line:

<temporary file name> <content type> <original file name>

The current code is available under

http://www.grid.net.ru/nginx/modules/nginx_upload_module-1.99.0.tar.gz

but it has a problem with generating header for error responses. Use it
on your own risk.

-- 
Regards,
Valery Kholodkov





More information about the nginx mailing list