I'm using flask for my application. I'd like to send an image (dynamically generated by PIL) to client without saving on disk.
Any idea how to do this ?
I'm using flask for my application. I'd like to send an image (dynamically generated by PIL) to client without saving on disk.
Any idea how to do this ?
It turns out that flask provides a solution (rtm to myself!):
First, you can save the image to a tempfile and remove the local file (if you have one):
Second, set the temp file to the response (as per this stackoverflow question):
I was also struggling in the same situation. Finally, I have found its solution using a WSGI application, which is an acceptable object for "make_response" as its argument.
Please replace "opening image" operations with appropriate PIL operations.
Here's a version without any temp files and the like (see here):
To use in your code simply do
Mr. Mr. did an excellent job indeed. I had to use BytesIO() instead of StringIO().