I am developing a web app, which has the functionality of displaying images obtained from a server. I learned that I can do it by returning byte array in response.
It seems that I am able to do it through:
@RequestMapping(value = "url/img", method = RequestMethod.POST)
@ResponseBody
public MyDto proceedDocumentFromUrl(@RequestParam final String url) throws IOException {
return somethingDoer.do(toByteArray(new URL(url).openStream());
}
somethingDoer.do
returns Dto object which contains byte[]
In field named image
. For test purposes I would like to determine the image extension (it is always .jpg).
How can I do that? I was looking in Wiki and W3 documents for some clue(I suppose it is about first few bytes) but was unable to find a solution.