java - Spring boot load image after upload -


i able upload image server , can locate image in path /static/images/gallery. when try load uploaded images application not displaying theme. after application restart.

the static directory loaded @ startup. when upload images or make changes files or folder under static folder not reflect applicationcontext initialized.

to upload dynamic image can follow these steps:

step 1: create directory outside static folder media created on server

/var/www/html/myapp/media 

step 2: upload files in media directory.

step 3: implement webmvcconfigurer.

@configuration public class additionalresourcewebconfiguration implements webmvcconfigurer {    @override   public void addresourcehandlers(final resourcehandlerregistry registry) {     registry.addresourcehandler("/media/**").addresourcelocations("file:media/");   } } 

once uploaded can access file http://localhost:8080/media/filename.jpg dynamically.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -