jQuery how to check if uploaded file is an image without checking extensions?

前端 未结 7 1278
有刺的猬
有刺的猬 2021-01-31 09:17

Newbie here. The problem is that I currently have written a method which checks uploaded file size and extension in order to validate it. However, checking extensions is not a s

7条回答
  •  再見小時候
    2021-01-31 10:02

    You could try to convert file type in string and after that slice this string like that:

    if(String(file.type).slice(0, 6) === 'image/') {....some code}
    

提交回复
热议问题