When I get the request, request.FILES is empty. Yet the content type is multipart/form-data and the method is POST:
(Pdb) print request.META['CONTENT_TYPE'] multipart/form-data; boundary="boundary_.oOo._NzEwNjIzMTM4MTI4NjUxOTM5OQ==MTY2NjE4MDk5Nw==" (Pdb) print request.META['REQUEST_METHOD'] POST (Pdb) print request.FILES <MultiValueDict: {}> The individual files are being sent with content-type 'application/octet-stream', and it looks like I get the contents of the files converted to unicode: (Pdb) type(request.POST['right-carotidartery:63B2E474-D690-445F-B92A-31EBADDC9D93.png']) <type 'unicode'> I've tried to decoding it with: unicodedata.normalize('NFKD', request.POST[key]).encode('ascii','ignore')) But that did not create a valid PNG file. It seems that something mistakenly encoded to unicode. What would be doing that? Any suggestions on how I can make this work? On Fri, Aug 19, 2016 at 5:56 PM, Aron Griffis <a...@scampersand.com> wrote: > Hi Larry, > > I think you'll find what you're looking for in request.FILES, see > https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.FILES > and https://docs.djangoproject.com/en/1.10/ref/files/uploads/#uploaded-files > > This is the same as using cgi.FieldStorage to parse files from a submitted > multipart/form-data. You can then call .read() on the UploadedFile object, > or better yet use .chunks() to copy to your final destination without > overwhelming memory. > > -Aron > > > 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/CACwCsY5Ps%2BFYvT8RwPRV5ant2QauQL_JaaH-ww-LzUMiyEddLg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.