How to check file MIME type with javascript before upload?

前端 未结 9 2257
挽巷
挽巷 2020-11-22 03:50

I have read this and this questions which seems to suggest that the file MIME type could be checked using javascript on client side. Now, I understand that the real validati

9条回答
  •  庸人自扰
    2020-11-22 04:45

    This is what you have to do

    var fileVariable =document.getElementsById('fileId').files[0];
    

    If you want to check for image file types then

    if(fileVariable.type.match('image.*'))
    {
     alert('its an image');
    }
    

提交回复
热议问题