On Mon, Aug 22, 2016 at 10:11:49AM -0400, Larry Martell wrote: > 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'>
Are you certain the request contains correct headers for files? In particular, look at the “Content-Disposition” header; for each file, it should contain the “filename” attribute; otherwise, Django will treat it as a regular (non-file) form field [1]. As an example, the header could look like this:: Content-Disposition: form-data; name="file"; filename="filename.png" > 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? By this point, it's too late – Django has already treated the field as a string field, so it's already called ``force_text(data, encoding, errors='replace')`` [2], which means the value you have there has already lost some information that is impossible to get back [3]. And even if it was reversible, performing a Unicode normalization, and then throwing away everything non-ASCII would most certainly not be the correct way, since it would mangle about one half of the input data into ASCII. > Any suggestions on how I can make this work? You'll have to make sure that the request is correct, I'm afraid. Good luck, Michal [1]: https://github.com/django/django/blob/a8f957797d8035a542cdb20b03aaebd81b9529e2/django/http/multipartparser.py#L638-L641 [2]: https://github.com/django/django/blob/a8f957797d8035a542cdb20b03aaebd81b9529e2/django/http/multipartparser.py#L207 [3]: https://docs.python.org/2/library/codecs.html#codec-base-classes -- 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/20160822150034.GM27882%40koniiiik.org. For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: Digital signature