What's the best way to return image data from a RESTful service?
The image is part of a model (e.g. a User model which may have a 'photo' property) which is being returned by the method call.
Is it best to return the binary data with the GET request. Or is it best to return a URL from which the client can access the image.
The former seems like it would be easier to encapsulate and allow for authentication.
I'm using Django and the Django Rest Framework.
Thanks
The GET response have more data than the binary file?.
If the answer is Yes, you must return your data in response + URL with the binary in the json data.
If the answer is No, you can return the raw image with the correct
content-type.
In general, mix text data and binary data is a bad idea.
Django, as a modern framework, allows you to securize the URL's in a easy way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With