I am developing a rest api using spring boot. I have an upload image service which stores images in my project workspace and image url in stored in db. I have an entity product which has a list of images. Now I have to return images back to the angular client.
I have two questions in mind:
Q1. Should I return just a list of image urls to the client? If yes how should client render images from those urls.
Q2. OR Should I return list of images itself? If yes please show me logic which is fast and efficient.
Q3. OR Should I return individual image one by one? If yes please tell me how.
Update:
Note: Since, Rest api is on one machine and Angular client is on another machine. I think that the image url needs some kind of prefix:
Suppose my project is in E:/myproject/ and images are in E:/myproject/images/image-name.jpg, so what should be prefix for image url.
Q1. Should I return just a list of image urls to the client? If yes how should client render images from those urls.
THIS. Since all you need to do next is to give those urls <img src="something.png" />
tags in the front end. This will also free the server from the responsibility of downloading the image and service it to the clients.
Q2. OR Should I return list of images itself? If yes please show me logic which is fast and efficient.
This is possible but very hard. I don't advise doing this since this will make the system download the image twice: first is from file storage to the backend, then 2nd is from backend to frontend.
Q3. OR Should I return individual image one by one? If yes please tell me how.
This is the approach you need to do if the images needs individual security when downloading. Securing your image downloads is possible with the 1st approach that you given, and again, this approach will make you download the image twice.
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