I am making a file upload POST API request to django app REST interface. This request is made from another django app view which is receiving the file from the form. I am using poster module
image = request.FILES['image']
from utils.poster.encode import multipart_encode
from utils.poster.streaminghttp import register_openers
register_openers()
datagen, headers = multipart_encode({'file':image.read()})
response = urlfetch.fetch(url="url",
payload=datagen,
method=urlfetch.POST,
headers=headers)
Am I missing any headers?. How django process request with multipart/form-data? This is the error i am getting.
multipart_yielder instance has no attribute '__len__'
GAE's UrlFetch cannot use the output returned by multipart_encode() for payload. UrlFetch.fetch is executing len() on the payload, and the payload returned by multipart_encode is a Python generator, which in general does not support len().
The workaround is to create a payload string first, but it will use lot of memory for large files.
datagen, headers = multipart_encode({'file':image.read()})
data = str().join(datagen)
response = urlfetch.fetch(url="url",
payload=data ,
method=urlfetch.POST,
headers=headers)
Issue was reported here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With