Determining unknown content-types with the Html5 file api

后端 未结 2 1829
隐瞒了意图╮
隐瞒了意图╮ 2021-02-13 23:02

I\'m working through a small file upload script (learning experience) and I noticed that when selecting microsoft office related files (.doc or .docx f

相关标签:
2条回答
  • 2021-02-13 23:49

    According to the W3 File Api Draft the type attributte:

    The ASCII-encoded string in lower case representing the media type of the Blob, expressed as an RFC2046 MIME type [RFC2046]. On getting, conforming user agents SHOULD return the MIME type of the Blob, if it is known. If conforming user agents cannot determine the media type of the Blob, they MUST return the empty string. A string is a valid MIME type if it matches the media-type token defined in section 3.7 "Media Types" of RFC 2616

    So basically, if it's not a valid or media-type of HTTP/1.1 it will be empty. Anyways.

    Yeah, you should do something like:

    if(type === "") {
      //Get extension and match to a MIME-types list. (http://www.htmlquick.com/es/reference/mime-types.html)
    }
    
    0 讨论(0)
  • 2021-02-13 23:58

    agree with the accepted answer, but as an FYI to someone (like me) who got stuck as to WHY this was happening for some and not others for specific file types, be aware that in Windows, if the mime isn't appropriately set in the users registry, you will get empty string. That was a fun few hours :)

    0 讨论(0)
提交回复
热议问题