These are chat archives for django/django

28th
Nov 2015
Sudheesh Singanamalla
@sudheesh001
Nov 28 2015 07:32

Hi Pythonistas, I've got a small query,I am building a small api wrapper in python for the loklak project, I am using the requests library to make a request to the server and retrieving an image response, How do i give this image as a response, the data is present in the request response r.content from which I can write the data to a file to create the image, but in case this api is being used by someone else, is it right to return r.content to the user ?

Here's a small snippet

import requests
url = 'http://loklak.org/vis/markdown.png?text=hello%20world%0Dhello%20universe&color_text=000000&color_background=ffffff&padding=3'
r = requests.get(url)
# f = open('image.png','wb')
# f.write(r.content)
# f.close()
return r.content

Any guidance would be really helpful. Thanks a lot :smile:

Ivlev Denis
@ivlevdenis
Nov 28 2015 10:51
Sudheesh Singanamalla
@sudheesh001
Nov 28 2015 18:00
@ivlevdenis the problem is not about the streaming , It's about, in case I create a obj.getImage() which had the above code which returns an image ... Should I really return the image content which is in r.content or is there a better way ?