Upload Module - add response header with MD5

Hi!
here is the snuppet of configuration I use for uploading:
location /upload {
auth_request /auth;
upload_pass /200;
upload_store /download 1;

            upload_resumable on;

            #Return download path to calling party in custom header

value
upload_add_header XXX-DownloadURI “$upload_tmp_path”;
#Return md5 file checksum to calling party as custome
header
value
upload_add_header X-XXX-MD5SizeChecksum
“$upload_file_md5”;
upload_add_header X-XXXXr-FileSize “$upload_file_size”;

            upload_aggregate_form_field "$upload_field_name.md5"

“$upload_file_md5”;
upload_aggregate_form_field “$upload_field_name.size”
“$upload_file_size”;

It works perfect, great job, thanks! Specially about upload_add_header.
However the MD5 hashes returned in response header are… not hashes.
They are:
34383765656261393461336230613362 OR
34396436323764343839623564646664
I can’t rely on them on caller side…

Could it be a problem with add_header? I assume that aggregate field is
generated correctly, however when setting it to header via
upload_add_header, there is an convertion mistake.

Many thanks in advance!
You are doing great Job

Posted at Nginx Forum:

On Sat, Aug 18, 2012 at 06:54:01AM -0400, mokriy wrote:

Hi there,

here is the snuppet of configuration I use for uploading:
location /upload {

            #Return download path to calling party in custom header

value
upload_add_header XXX-DownloadURI “$upload_tmp_path”;

What does “nginx -V” show?

This is a way of asking “what upload module are you using that has
‘upload_add_header’?”

Thanks,

f

Francis D. [email protected]

Hi Francis!
Many thanks for you reply.

Basically, I am using the one from Valeriy Kholodkov:
http://www.grid.net.ru/nginx/upload.ru.html

upload_add_header feature appeared in v 2.2, I guess:
https://github.com/vkholodkov/nginx-upload-module/blob/2.2/ngx_http_upload_module.c
I can find it in C code - ‘upload_add_header’.

Posted at Nginx Forum:

Oh, many thanks Francis…
That is tricky.

Ok, will try.

To get my current flow working, I will use variable assignment in nginx
and
set variable a value with aggregate field.
So, I can reuse it without calling aggregation several times.

Posted at Nginx Forum:

Aggregate variables cannot be used in upload_add_header directive,
because they are not valid outside of a request body part.

----- mokriy [email protected] wrote:

value

Many thanks in advance!
You are doing great Job


Regards,
Valery K.

On Mon, Aug 20, 2012 at 03:28:59AM -0400, mokriy wrote:

Hi there,

Basically, I am using the one from Valeriy Kholodkov:
Nginx upload module (v 2.2.0)

upload_add_header feature appeared in v 2.2, I guess:

Ah, you’re using a development work-in-progress version.

upload_add_header is not in the released 2.2.0 tarball.

https://github.com/vkholodkov/nginx-upload-module/blob/2.2/ngx_http_upload_module.c

I can find it in C code - ‘upload_add_header’.

I guess you’ve found a bug in the development code.

However the MD5 hashes returned in response header are… not hashes.
They are:
34383765656261393461336230613362 OR
34396436323764343839623564646664

It looks like it isn’t a new bug in the post-2.2.0 code; but
upload_add_header makes it easier to expose.

It appears that (at least) for the aggregate variables, accessing one
more than once will cause the previous value to be read as bytes, and
written in hexadecimal ascii representation.

So in your first example above, the md5sum began 487eeba94a3b0a3b.

Test with something like

upload_aggregate_form_field "${upload_field_name}_md5" 

$upload_file_md5;
upload_aggregate_form_field “${upload_field_name}_md6”
$upload_file_md5;
upload_aggregate_form_field “${upload_field_name}_md7”
$upload_file_md5;
upload_aggregate_form_field “${upload_field_name}_md8”
$upload_file_md5;

and you’ll see that the later values include increasing strings of 3s.

(Of course, it was never sane to use $upload_file_md5 more than once,
so this didn’t matter. But now it is, and it does.)

f

Francis D. [email protected]