Featured post
How to get binary post data in Django !nicely? -
forgive me if bit of newbie question, started learn django yesterday, , i'm trying not bad habits, i.e. trying things "the django way" start.
i have view recieves binary data http post field. django of course autoconverts binary data unicode string.
my question is, how raw binary data?
a couple of things occurred me. let request request i'm processing.
- using
request.raw_post_datainvolve parsing data again - when appearantlyrequest.poststores raw data , trying around on-the-fly conversion (and besides, new in development version). - using base64 or transfer data work, seems overhead when data transfer not problem.
- doing
request.encoding="foo"before getting field (and reassigning afterwards) doesn't work either because still unicode string, besides feeling bit of dirty hack. using"base64"here (not bad transfer encoding) gives meassertionerror.
thanks in advance ideas!
edit: clarify - not talking classic file upload here, binary data stored in post field. i'd way because way want interface view via upload script. using normal post field makes both client , server simpler in case.
some might storing binary data in standard form field bad habit in way :)
you use standard library methods of python convert string binary representation.
take @ binascii — convert between binary , asci
posting before edit:
what piece of code (receiving data post)
def handlefile(self, request): file = request.files["file"] destination = open('filename.ext', 'wb') chunk in file.chunks(): destination.write(chunk) destination.close() works me.
- Get link
- X
- Other Apps
Comments
Post a Comment