0

So I have a file (uploaded using form) and I think the best way to validate if the image is an actual image is to actually create a new Image class of that file?

How can I make it so I can use the file to initiate a new image instance?

const fileFromForm = files[0];
const img = new Image();
const img.src = fileFromForm; // not sure if this will work ???
I am L
  • 2,336
  • 2
  • 19
  • 35
  • 1
    Note regarding the dupe: The accepted answer should not be used, it uses too much memory for nothing. Instead prefer the first solution described in [that answer](https://stackoverflow.com/a/27165977/3702797). – Kaiido Feb 18 '20 at 08:38
  • @Kaiido -san, but will this throw an error if the "url" or the file is a video? (I saw this answer earlier too but got confused) – I am L Feb 18 '20 at 08:54
  • 1
    Yes, to load a video, use – Kaiido Feb 18 '20 at 08:57

0 Answers0