0

I have a case where I have an image file inside assets directory. I know the filename at runtime but I don't know what's its type upfront. It can be: logo.png, logo.svg or logo.jpeg. I know I can check if given file exists (see: how can i check if image exists in assets folder using angular 4) but it can affect application`s performance. Is there a better way to create source to the image?

Mateusz Witkowski
  • 1,646
  • 10
  • 24
  • WHat is your purpose ? Giving context would greatly help. –  Mar 13 '18 at 08:23
  • It's prettye simple. Image file is uploaded by user to the server (outside of my Angular app) and then pushed by backend service into dist folder (into assets directory). It can have three formats (png, svg, jpeg) so I'm wondering how to create some kind of 'universal' src path for it. I'm looking for most efficient way to do it. – Mateusz Witkowski Mar 13 '18 at 08:26
  • Then why don't you save the extension when you store it in your database ? –  Mar 13 '18 at 08:27
  • I'd very like to to that but unfortunately for some unrelated reasons it's not possible in this case. – Mateusz Witkowski Mar 13 '18 at 08:28
  • 1
    Then your only solution is the one you found ... On the client side, in a web application, you can't read a folder, only a server can (from my personal knowledge of course). And don't worry about performance issues, if you try to load 4 images, it won't crash your app :) –  Mar 13 '18 at 08:32

0 Answers0