Checking HTML5 drag and drop file type

前端 未结 3 691
野趣味
野趣味 2021-02-08 09:52

I\'d like to change drop zone background color to green or red depending on whether the contained drag over payload contains supported file types (JPEG).

  • Do Ge

3条回答
  •  忘了有多久
    2021-02-08 10:38

    I don't think you can rely on the browser to give you the MIME type. It'd be much simpler if you checked the filename extension. :)

    If you really want to check the file type, read the payload using DataTransfer.getData() and check the leading bytes (PNG, GIF89, JFIF or something).

提交回复
热议问题