How to detect file extension with javascript FileReader

后端 未结 2 869
再見小時候
再見小時候 2020-12-10 11:09

I\'m using javascript\'s FileReader and my customized function for reading an JPG-JPEG image, My problem is that how it\'s possible to detect the file extension through my c

2条回答
  •  借酒劲吻你
    2020-12-10 11:45

    There's not a direct interface to read the file extension. You have at least 2 options:

    • Use a regex to extract the extension from the filename
    • Use the content type of the file as your filter

    For the extension method it'd be something like:

    var extension = fileName.match(/\.[0-9a-z]+$/i);
    

提交回复
热议问题