How to check file MIME type with javascript before upload?

前端 未结 9 2101
挽巷
挽巷 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:51

    Here is an extension of Roberto14's answer that does the following:

    THIS WILL ONLY ALLOW IMAGES

    Checks if FileReader is available and falls back to extension checking if it is not available.

    Gives an error alert if not an image

    If it is an image it loads a preview

    ** You should still do server side validation, this is more a convenience for the end user than anything else. But it is handy!

    Image Preview

提交回复
热议问题