[Django]-Django request.FILES is empty

3👍

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.

Leave a comment