On Mon, Aug 22, 2016 at 12:11 PM, Bill Freeman <ke1g...@gmail.com> wrote: > The most appropriate thing is for the source to use the correct content > type, in which case I believe that Django just works (it certainly used to). > But I'm assuming that you can change that. The stuff I suggested were hacks > and as such are things you do in a darkened room and keep secret. Note that > you want to recognize when it's one of these uploads before applying the > chosen hack(s).
One man's hack is another man's elegant solution ;-) > On Mon, Aug 22, 2016 at 10:53 AM, Larry Martell <larry.mart...@gmail.com> > wrote: >> >> On Fri, Aug 19, 2016 at 4:58 PM, Bill Freeman <ke1g...@gmail.com> wrote: >> > If the original data truly isn't on the request object somewhere, you >> > might >> > be able to grab it earlier by writing a request midleware. You might >> > have >> > to put it pretty early in the chain. >> > >> > The first thing to try is changing the content_type to something more >> > appropriate, >> >> What would be more appropriate? >> >> > and see if the data shows up in request.FILES (but my >> > experience here is older, and things may or may not still work this way >> > in >> > newer django's. >> > >> > Somewhat harder is that request.POST[key]'s conversion to unicode might >> > be >> > reversible, though not necessarily with an existing codec. >> > >> > Finally, you might suck down and decode the request data yourself in the >> > middleware, and either save the file and return a response yourself, or >> > fix >> > the request up so that the rest of the middlewares and the view won't be >> > upset. >> > >> > Good luck, and I hope someone gives you a better answer. >> > >> > Bill >> > >> > On Fri, Aug 19, 2016 at 4:17 PM, Larry Martell <larry.mart...@gmail.com> >> > wrote: >> >> >> >> I have a falcon server that I am trying to port to django. One of the >> >> falcon endpoints processes a request that contains a PNG file sent >> >> with content_type = 'application/octet-stream'. It writes the data to >> >> a file maintaining the correct PNG structure. >> >> >> >> The falcon code does this: >> >> >> >> form = cgi.FieldStorage(fp=req.stream, environ=req.env) >> >> >> >> and then writes the png like this: >> >> >> >> fd.write(form[key].file.read()) >> >> >> >> I cannot figure out how to do the same thing in django. When my view >> >> is called the data in request.POST[key] has already been decoded to >> >> unicode text and it's no longer valid png data. >> >> >> >> How can I do this with django? Should/can I use cgi.FieldStorage? The >> >> request I get (of type django.core.handlers.wsgi.WSGIRequest) does not >> >> have a stream method. I'm sure there's some way to do this, but I have >> >> not come up with anything googling. >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> >> Groups >> >> "Django users" group. >> >> To unsubscribe from this group and stop receiving emails from it, send >> >> an >> >> email to django-users+unsubscr...@googlegroups.com. >> >> To post to this group, send email to django-users@googlegroups.com. >> >> Visit this group at https://groups.google.com/group/django-users. >> >> To view this discussion on the web visit >> >> >> >> https://groups.google.com/d/msgid/django-users/CACwCsY5m4fdczXdQ0gYX61gBe0BYQ-ZoZ1R_vpkrGEzv%2B2-vBg%40mail.gmail.com. >> >> For more options, visit https://groups.google.com/d/optout. >> > >> > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACwCsY5Rk63M_GEsdRmTay32%3D7g-SVJxW0PcTaz5GhMuH_UEQQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.