tags:

views:

11

answers:

1

Hi:

I'm defining a create() method in django-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?

A: 

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.

chubbard