Spring-MVC, Java : Creating URL for image saved on FileSystem -


i working on spring-mvc application in user, saving thumbnail on filesystem itself. chat, want create url thumbnail saved on filesystem , pass on in frontend.

for example : image saved @

/home/username/datadir/personid.png 

i give url :

domainname.com/personid.png 

please note personid unique, can use constraint. part save image complete, don't know how create image url out of file saved on file-system.

any nice. lot.. :-)

you should intermediate call request handler, like

@requestmapping("/image/{personid}") @responsebody public httpentity<byte[]> getphoto(@pathvariable string personid) {     byte[] image = org.apache.commons.io.fileutils.readfiletobytearray(new file([your path] + file.separator + personid + ".png"));      httpheaders headers = new httpheaders();     headers.setcontenttype(mediatype.image_png);      headers.setcontentlength(image.length);     return new httpentity<byte[]>(image, headers); } 

note can use content analysis determine proper media type e.g. of apache tika. way don't have store filename, or hard-code extension


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -