Fix file upload not chunked#327
Fix file upload not chunked#327fafhrd91 merged 3 commits intoaio-libs:masterfrom hoh:upload_nochunked
Conversation
The upload of a single file is not chunked anymore as the content-length can be determined, except if the chunked argument is passed forced as True. This fixes #126 for uploading a single file, but does not apply to multipart uploads.
|
@kxepal could you review this PR? |
aiohttp/client.py
Outdated
There was a problem hiding this comment.
What if file was read a bit before it's going to be sent with a request?
with open('foo.bar', 'rb') as f:
magic = f.read(3)
...
yield from aiohttp.request('post', 'http://localhost/upload', data=f)
In this case Content-Length header will declare more bytes than actually could be sent. Use tell() to figure out how much were already read. Also, since you have file description here, you can do just os.fstat(data.fileno()).st_size what is a bit more efficient.
There was a problem hiding this comment.
Thx, I'll have a look at that.
There was a problem hiding this comment.
Fixed both seeking and more efficient file size access.
|
@fafhrd91 sure. |
There was a problem hiding this comment.
I would use full os.fstat here since it doesn't simply to figure out what fstat is and where it comes from. Also look on the other imports from stdlib.
|
LGFM expect the import thing. Please, squash all the commits and it will be ready for merge (: |
|
Thanks, Hugo! |
|
@kxepal looks like your request for |
|
@asvetlov yes, fixed that. thanks for notice! |
The upload of a single file is not chunked anymore as the content-length can be determined,
except if the chunked argument is passed forced as True.
This fixes #126 for uploading a single file, but does not apply to multipart uploads.