# Upload Module - add response header with MD5

**URL:** <https://www.ruby-forum.com/t/upload-module-add-response-header-with-md5/222232>\
**Category:** NGINX\
**Created:** [August 18, 2012, 12:54pm UTC](https://www.ruby-forum.com/t/upload-module-add-response-header-with-md5/222232 "2012-08-18T12:54:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [August 18, 2012, 12:54pm UTC](https://www.ruby-forum.com/t/upload-module-add-response-header-with-md5/222232/1 "2012-08-18T12:54:35Z")

</div>

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:

> **[Upload Module - add response header with MD5](https://forum.nginx.org/read.php?2,229882,229882#msg-229882)**
>
> 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;

---

<div class="post-metadata">

**Author:** ![mokriy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/848f3c/32.png) [@mokriy](https://www.ruby-forum.com/u/mokriy)\
**Post date:** [August 19, 2012, 1:37am UTC](https://www.ruby-forum.com/t/upload-module-add-response-header-with-md5/222232/2 "2012-08-19T01:37:35Z")

</div>

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. removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![mokriy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/848f3c/32.png) [@mokriy](https://www.ruby-forum.com/u/mokriy)\
**Post date:** [August 20, 2012, 9:29am UTC](https://www.ruby-forum.com/t/upload-module-add-response-header-with-md5/222232/3 "2012-08-20T09:29:35Z")

</div>

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](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](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:

> **[Re: Upload Module - add response header with MD5](https://forum.nginx.org/read.php?2,229882,229917#msg-229917)**
>
> 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;

---

<div class="post-metadata">

**Author:** ![mokriy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/848f3c/32.png) [@mokriy](https://www.ruby-forum.com/u/mokriy)\
**Post date:** [August 21, 2012, 9:53am UTC](https://www.ruby-forum.com/t/upload-module-add-response-header-with-md5/222232/4 "2012-08-21T09:53:21Z")

</div>

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:

> **[Re: Upload Module - add response header with MD5](https://forum.nginx.org/read.php?2,229882,229941#msg-229941)**
>
> 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;

---

<div class="post-metadata">

**Author:** ![mokriy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/848f3c/32.png) [@mokriy](https://www.ruby-forum.com/u/mokriy)\
**Post date:** [August 27, 2012, 2:01pm UTC](https://www.ruby-forum.com/t/upload-module-add-response-header-with-md5/222232/5 "2012-08-27T14:01:20Z")

</div>

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

----- mokriy [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> value
> 
> Many thanks in advance!  
> You are doing great Job

–  
Regards,  
Valery K.

---

<div class="post-metadata">

**Author:** ![mokriy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/848f3c/32.png) [@mokriy](https://www.ruby-forum.com/u/mokriy)\
**Post date:** [August 20, 2012, 9:19pm UTC](https://www.ruby-forum.com/t/upload-module-add-response-header-with-md5/222232/6 "2012-08-20T21:19:36Z")

</div>

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)](http://www.grid.net.ru/nginx/upload.ru.html)
> 
> 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](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. removed\_email\_address@domain.invalid
