# Upload module parameters issue

**URL:** <https://www.ruby-forum.com/t/upload-module-parameters-issue/212467>\
**Category:** NGINX\
**Created:** [October 4, 2011, 2:35am UTC](https://www.ruby-forum.com/t/upload-module-parameters-issue/212467 "2011-10-04T02:35:58Z")\
**Posts on this page:** 4\
**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:** [October 4, 2011, 2:35am UTC](https://www.ruby-forum.com/t/upload-module-parameters-issue/212467/1 "2011-10-04T02:35:58Z")

</div>

Thanks very much, that really helped!

> On Mon Oct 3 19:04:22 UTC 2011, Andrew H. wrote:
> 
> Hi there,
> 
> > - 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}\_sha1” $upload\_file\_sha1;_\> \>_  
> upload\_aggregate\_form\_field “${upload\_field\_name}\_size” $upload\_file\_size;\*\>  
> Note that “resumable” can apply to a single file, without any  
> $upload\_field\_name set, so you’ll get things like “\_name” and  
> “\_content\_type” in your final post content.

What would be the right way to get the $upload\_field\_name populated?  
Or should I even worry about that? I don’t imagine that my usage will  
care about it (I’m going to be including the module and uploading a  
single file at a time), however I’d like the library code to not suck  
too much for the next guy.

> - 
> 
> ```
> top_bound = plus_chunk if plus_chunk < self.total_file_size else 
> 
> ```

self.total\_file\_size - 1

> ```
> return 'bytes %d-%d/%d' % (self.last_byte_uploaded, top_bound, 
> 
> ```

self.total\_file\_size)

> ```
> @property
> 
> ```
> 
> > - Please note that despite the error message on line 680, the uploaded file  
> > is\*\> \>\* byte-for-byte identical to the source file. Error message follows:_\> \>_ \*\>
> 
> - 2011/10/03 10:58:46 [error] 8111#0: _35 file offset at the end of a part_\> \>\*  
> 210000 does not match the end specified range 204796-210000/210000, client:_\> \>_  
> 10.178.51.115, server: [account.nutricateonline.com](http://account.nutricateonline.com), request: “POST\*\> \>\*  
> /rspool/?a=b&c=d HTTP/1.0”, host: “209.114.46.109”\*\>  
> The range is expected to be 204796-209999/210000, as patched above.

Patch applied, thanks! I also updated my UTs to reflect this change  
(and the 50kb default chunk size).

> > - I think that having request.FILES empty is correct. The two parameters in\*\>
> 
> - the GET dictionary are from the command line (also correct). However I think\*\>
> - the upload parameters should be represented somewhere. Can anyone suggest\*\> \>\*  
> next steps?\*\>  
> They’ll be in the POST dictionary when the client is right.

Yup, they’re there now. Perfect!

> Note that you are also double-sending the last byte of each chunk –  
> make chunk\_size be 1 or 2 and send a small file, and you’ll see the  
> problem. The receiving side can handle the double-send, so it’s an  
> inefficiency rather than a protocol error.

I’ll root this bug out later, for now it appears to be working  
end-to-end.

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [October 4, 2011, 6:27pm UTC](https://www.ruby-forum.com/t/upload-module-parameters-issue/212467/2 "2011-10-04T18:27:31Z")

</div>

On Mon Oct 3 19:04:22 UTC 2011, Andrew H. wrote:

Hi there,

> 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}\_sha1” $upload\_file\_sha1;  
> upload\_aggregate\_form\_field “${upload\_field\_name}\_size” $upload\_file\_size;

Note that “resumable” can apply to a single file, without any  
$upload\_field\_name set, so you’ll get things like “\_name” and  
“\_content\_type” in your final post content.

> I upload to the system using the following (see  
> [https://github.com/SmartReceipt/py\_lightweight\_uploader](https://github.com/SmartReceipt/py_lightweight_uploader)):

One important off-by-one error there:

— py\_lightweight\_uploader.py 2011-10-03 23:37:18.000000000 +0100  
+++ py\_lightweight\_uploader.py 2011-10-03 23:40:24.000000000 +0100  
@@ -188,7 +188,7 @@  
@property  
def next\_content\_range(self):  
plus\_chunk = self.last\_byte\_uploaded + self.chunk\_size - 1

- 

```
   top_bound = plus_chunk if plus_chunk < self.total_file_size 

```

else self.total\_file\_size

- 

```
   top_bound = plus_chunk if plus_chunk < self.total_file_size 

```

else self.total\_file\_size - 1  
return ‘bytes %d-%d/%d’ % (self.last\_byte\_uploaded, top\_bound,  
self.total\_file\_size)

```
 @property

```

> Please note that despite the error message on line 680, the uploaded file is  
> byte-for-byte identical to the source file. Error message follows:
> 
> 2011/10/03 10:58:46 [error] 8111#0: \*35 file offset at the end of a part  
> 210000 does not match the end specified range 204796-210000/210000, client:  
> 10.178.51.115, server: [account.nutricateonline.com](http://account.nutricateonline.com), request: “POST  
> /rspool/?a=b&c=d HTTP/1.0”, host: “209.114.46.109”

The range is expected to be 204796-209999/210000, as patched above.

> I think that having request.FILES empty is correct. The two parameters in  
> the GET dictionary are from the command line (also correct). However I think  
> the upload parameters should be represented somewhere. Can anyone suggest  
> next steps?

They’ll be in the POST dictionary when the client is right.

Note that you are also double-sending the last byte of each chunk –  
make chunk\_size be 1 or 2 and send a small file, and you’ll see the  
problem. The receiving side can handle the double-send, so it’s an  
inefficiency rather than a protocol error.

But with 50kB chunks, that last range should really be  
204800-209999/210000.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [October 4, 2011, 10:49pm UTC](https://www.ruby-forum.com/t/upload-module-parameters-issue/212467/3 "2011-10-04T22:49:53Z")

</div>

On Tue, Oct 4, 2011 at 10:06 AM, Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > What would be the right way to get the $upload\_field\_name populated?  
> > Or should I even worry about that? I don’t imagine that my usage will  
> > care about it (I’m going to be including the module and uploading a  
> > single file at a time), however I’d like the library code to not suck  
> > too much for the next guy.
> 
> I’d say “don’t worry about it”.

Done. I refactored the code to clean it up a little and correct that  
overlap  
bug. It’s on github and can be forked if anyone wants to go further.

My last (I think) issue is that I’m seeing most, but not all of the  
upload  
form fields get set. The sha1, md5 and crc32 aggregates below are  
blanks.

request.POST \<QueryDict: {  
u’upload\_name’: [u’py\_lightweight\_uploader.py’],  
u’upload\_size’: [u’11345’],  
u’upload\_sha1’: [u’‘],  
u’upload\_content\_type’: [u’text/x-python’],  
u’upload\_path’: [u’/var/lib/nginx/resumable\_download/7/64565707’],  
u’upload\_md5’: [u’‘],  
u’upload\_crc32’: [u’']}\>

I see that libssl is installed on the server. I don’t see any entries in  
the  
error log that would make me think there is anything failing here. I  
have  
the following in the nginx config:

upload\_set\_form\_field upload\_name $upload\_file\_name;  
upload\_set\_form\_field upload\_content\_type $upload\_content\_type;  
upload\_set\_form\_field upload\_path $upload\_tmp\_path;  
upload\_aggregate\_form\_field upload\_sha1 $upload\_file\_sha1;  
upload\_aggregate\_form\_field upload\_size $upload\_file\_size;  
upload\_aggregate\_form\_field upload\_crc32 $upload\_file\_crc32;  
upload\_aggregate\_form\_field upload\_md5 $upload\_file\_md5;

I based the above on the documentation and example config. What am I  
missing  
here?

Andrew

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [October 4, 2011, 7:06pm UTC](https://www.ruby-forum.com/t/upload-module-parameters-issue/212467/4 "2011-10-04T19:06:59Z")

</div>

On Mon, Oct 03, 2011 at 05:35:05PM -0700, Andrew H. wrote:

Hi there,

> Thanks very much, that really helped!

> > Note that “resumable” can apply to a single file, without any  
> > $upload\_field\_name set, so you’ll get things like “\_name” and  
> > “\_content\_type” in your final post content.
> 
> What would be the right way to get the $upload\_field\_name populated?  
> Or should I even worry about that? I don’t imagine that my usage will  
> care about it (I’m going to be including the module and uploading a  
> single file at a time), however I’d like the library code to not suck  
> too much for the next guy.

I’d say “don’t worry about it”.

To upload multiple files, you use a form, which will set  
$upload\_field\_name for each file.

Resumable upload with a single file just needs a single set of  
variables,  
so an empty prefix is fine.

All the best,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
