Issue #13 new

multipart_encode first n bytes of a file

brianwill
created an issue

I'm attempting to send just the first n bytes of a file, but either I'm doing it wrong or poster makes no such allowance. This code works for me when I send the whole file: {{{

!python

f = open(filePath, 'rb')
datagen, headers = multipart_encode({'file': f})

}}}

I thought this would work for a partial file, but it doesn't:

{{{

!python

f = open(filePath, 'rb')
mp = MultipartParam('file', fileobj=f, filesize=1000) # send just first 1000 bytes
datagen, headers = multipart_encode([mp])

}}} In fact, even if I pass a list of MultipartParams to multipart_encode without the filesize option, I'm getting errors from urllib2.urlopen or requests that hang and timeout.

Is this something that should work? If not, could you add in a way to send just the first n bytes?

Comments (1)

  1. Chris AtLee repo owner

    Hi,

    Right now poster assumes that you're going to be sending the entire file, and relies on the behaviour of file.read() to know when to stop sending data.

    I think the easiest way forward for this right now is to create a wrapper around f that returns only the first 1000 bytes from its read() method.

  2. Log in to comment