Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get binary post data in Django !nicely?
    text
    copied!<p>forgive me if this is a bit of a newbie question, I started to learn Django yesterday, and I'm trying not to get into bad habits, i.e. I am trying to do things "the django way" from the start.</p> <p>I have a view that recieves binary data as a http post field. Now Django of course autoconverts my binary data to a unicode string.</p> <p>My question is, how do I just get the raw binary data?</p> <p>A couple of things occurred to me. Let <code>request</code> be the request I'm processing.</p> <ul> <li>Using <code>request.raw_post_data</code> would involve parsing the data <em>again</em> - when appearantly <code>request.POST</code> actually stores raw data and I am actually just trying to get around the on-the-fly conversion (and besides, that is new in the development version).</li> <li>Using base64 or so to transfer the data would work, but seems like too much overhead when the data transfer itself is not the problem.</li> <li>doing <code>request.encoding="foo"</code> before getting that field (and reassigning afterwards) doesn't work either because I still get a unicode string, besides feeling like a bit of a dirty hack. Using <code>"base64"</code> here (not as bad as for the transfer encoding) gives me an <code>AssertionError</code>.</li> </ul> <p>Thanks in advance for your ideas!</p> <p>EDIT: To clarify - I am not talking about a classic file upload here, but as binary data stored in a POST field. I'd like to do it that way because the only way I want to interface with that view is via an upload script. Using a normal POST field makes both the client and the server much simpler in that case.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload