sending a file chunk by chunk instead as a whole to a web server

Kushal Kumaran kushal.kumaran+python at gmail.com
Tue Aug 3 01:15:27 EDT 2010


On Mon, Aug 2, 2010 at 12:22 PM, Sanjeeb <sanjeeb25 at gmail.com> wrote:
> Hi,
> I have a web client which send a file to a server as multipart form
> data, the sending of data is from
> http://code.activestate.com/recipes/146306-http-client-to-post-using-multipartform-data/.
>
> I dont want to open the whole file to memory(at cliend end) and then
> send, i just want to send part by part, say chunk of 1024 bytes to the
> server and then assemble at the server end.
>
> Could some one suggest what would be the best way to do this?
>

There's no reason why sending the whole file implies reading the whole
file into memory at one time.  You can just read your desired chunk
size and send it, then read the next chunk, and so on.  You might have
to first find the total size to calculate what to set Content-Length
to.

ISTR questions of this nature have been asked in the past on this list.

-- 
regards,
kushal



More information about the Python-list mailing list