reading binary from django.core.files.uploadedfile.TemporaryUploadedFile

126 views
Skip to first unread message

Larry Martell

unread,
Jan 17, 2018, 12:02:27 PM1/17/18
to django...@googlegroups.com
I have a django app that runs on both linux and windows. One request
that it processes contains PNG files encoded as an octet-stream on the
client. The server gets an object of type
django.core.files.uploadedfile.TemporaryUploadedFile and it does this
to save the files on disk:

with open(fn, 'wb') as fd:
fd.write(request.FILES[key].read())

When the server is running on linux this works perfectly - i.e. the
PNG files are saved to disk properly and can be opened and viewed. But
when the server is running in Windows the PNG files are corrupt when
saved. I don't really know why that is, but my WAG is that it's due to
the file being binary. I did try this but it still failed:

with open(request.FILES[key], 'rb') as fd:
data = fd.read()
with open(fn, 'wb') as fd:
fd.write(data)

So perhaps that is not the issue. Anyone have any idea on what could
be the issue and/or how I can debug this?
Reply all
Reply to author
Forward
0 new messages