POSTing JPG|PNG along with JSON description with django-piston
I'm defining a create()
method in d开发者_如何学Gojango-piston. I need to be able to receive and image with its description enconded in JSON. How to do it? Shall they be processed in two separate HTTP requests?
I'd suggest posting your file as a multi-part encoded form just like your web browser does when you upload a file through a form. With multi-part encoding you can send the file as binary data element in your form (much better than BASE64 encoding your JPG in JSON), and then another element that holds your JSON data. It's one request. There are plenty of libraries out there that parse things in this form so it's easy to do.
精彩评论