Detect mime type of an image via Javascript

前端 未结 2 1571
粉色の甜心
粉色の甜心 2021-01-17 15:23

i am detecting images on my webpage with javascript document.images function which returns an rray of images. Is there any way to get the mime type of the image from this si

2条回答
  •  春和景丽
    2021-01-17 16:14

    According with other answers, I got pretty surprised to find out it was apparently not possible without requesting the image again. (??? That seems weird to me but oh well…)

    Another hacky-but-might-be-enough-for-your-use-case-solution that comes in my mind would be to:

    Parse the img.src in an attempt of guessing the file type.

    • "Guessing?" you may ask…
    • Yes because the extension might not be included in the src or could be misleading.

提交回复
热议问题