Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should REST Get request return image or image URL?

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

like image 656
ahallan Avatar asked Oct 24 '25 17:10

ahallan


1 Answers

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.

like image 57
José Ricardo Pla Avatar answered Oct 26 '25 07:10

José Ricardo Pla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!