send PIL.Image to django server side and get it back
José María Mateos
chema at rinzewind.org
Thu Jul 19 18:49:14 EDT 2018
On Mon, Jul 16, 2018 at 06:40:45AM -0700, Christos Georgiou - ΤΖΩΤΖΙΟΥ wrote:
> You need first to serialize the object to bytes that can go over the
> wire. There is no predefined way to do that, so you can:
>
> >>> import io
> >>> file_like_object = io.BytesIO()
> >>> PILImage.save(file_like_object, format='png')
>
> and then in your POST request send file_like_object.getvalue() as the
> image data. You will most probably need to add a Content-Type:
> image/png as a header.
If you definitely need to send the data as a string, because you want to
use a JSON object or similar, I've done this in the past using base64
encoding.
https://docs.python.org/2/library/base64.html
Cheers,
--
José María (Chema) Mateos
https://rinzewind.org/blog-es || https://rinzewind.org/blog-en
More information about the Python-list
mailing list