I’m trying to crate ImageController that contains following method:
public byte[] getProfileImage(@PathVariable String username) {
byte[] tmp = null;
tmp = imageService.getProfileImage(username).getImagefile();
return tmp;
}
Now if imageService return empty image file, i would like to load image from webapp/WEB-INF/img/ folder. I tried googling this but didn’t find any answer that i could get working.
Another way to do this would be loading image file in imageService class, but i don’t how could i load image from there either.
I would appreciate quite specific answer. Im not very skilled with spring. Especially configurations are not very clear to me.
You’re looking for the method ServletContext.getResourceAsStream(), which loads a resource from a path starting at the webapp’s root folder: