1

I have made an angular 6 project that connects to a back-end and fetches some data. The user of the application may upload pictures to the server, which I save inside the assets folder of my angular project.

I have noticed that when a pictured is saved in the folder, the front end will not display it (the img element will appear "broken") until the angular project is recompiled. Is this observation actually the reason the pictures don't load immediately?

What can I do about this?

Theo Stefou
  • 389
  • 2
  • 16
  • Yep, the `ng serve` will not reload assets when they're updated. Use your backend to fetch the images instead – user184994 Aug 12 '18 at 19:01
  • The back-end determines the names of the files and returns the path to the front end. – Theo Stefou Aug 12 '18 at 19:03
  • What I mean by that is: when the user uploads an image, the back end stores it in the assets folder and returns the path to the front end. Should I be saving the images somewhere else? – Theo Stefou Aug 12 '18 at 19:04
  • Yes, don't store them in the Angular assets file. Store them on a directory that's accessible to the backend, and use the backend to serve that directory as static assets. – user184994 Aug 12 '18 at 19:06
  • ok but then what would the path be? – Theo Stefou Aug 12 '18 at 19:07
  • It really depends how you configure the backend. Assuming your backend is at `localhost:8080`, you can configure it to serve your static assets behind the `static` path, so `localhost:8080/static/` + any sub-directories you've stored the image in + the image file name. – user184994 Aug 12 '18 at 19:10
  • my back end is listening at localhost:8080. To which folder in my pc does that correspond? When I used xampp with php for example, I knew that the first part of the hierarchy was in the www folder – Theo Stefou Aug 12 '18 at 19:11
  • I have no idea how your backend is configured... – user184994 Aug 12 '18 at 19:12
  • ok, how can I find out where the "root" folder of localhost:8080 is? – Theo Stefou Aug 12 '18 at 19:16
  • Which backend language / framework are you using? – user184994 Aug 12 '18 at 19:17
  • I am running java with jersey restful on glassfish5 and I am using intellij as my IDE if that helps – Theo Stefou Aug 12 '18 at 19:19
  • Take a look at https://stackoverflow.com/questions/37009898/serve-static-content-with-jersey-2-22-2 for a guide to serve static content with Jersey – user184994 Aug 12 '18 at 19:21
  • The thing is, I don't have a static folder in my project though. Can I just create one? – Theo Stefou Aug 13 '18 at 08:59
  • Yep, just create one. This will become the directory you should save your images to – user184994 Aug 13 '18 at 16:53

0 Answers0