Question

I have a Django view which accepts an uploaded file over PUT. I've created my own upload handler and am processing the data in chunks like so:

handler = MD5ChecksumUploadHandler()
handler.new_file(field_name="file", file_name="unknown",
                 content_type=request.META.get('CONTENT_TYPE', 'application/octet-stream'),
                 content_length=int(request.META.get('CONTENT_LENGTH', 0)))

upload_size = 0

while True:
    # read the request body in chunks
    chunk = request.read(handler.chunk_size)

    if chunk:
        handler.receive_data_chunk(chunk, start=None)
        upload_size += len(chunk)
    else:
        break

# return the MD5ChecksumUploadedFile
return handler.file_complete(upload_size)

As I've found out, the request.read method starts reading at the beginning of the actual request and not the request body. This causes my MD5 checksums to fail, which is incidentally good, as I know that something's going wrong.

Is there a way for me to read the actual request body rather than just the raw request?

Was it helpful?

Solution

The request I was making was a bad one, that's what my problem was:

Content-MD5\n: XXXXXXXXXXXXXXXXXXXXX

Check your request if you're having this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top