1

Is there a way to different the file passed to <input type="file"> elements? I need to know the type of file the user passed so I can read it afterwards with the HTML5 fileReader API either with readAsDataURL or readAsText based on type.

here is a live example of what my code looks like: http://jsfiddle.net/tdq3socz/1/

I understand that the instance of File I'm getting from the input element contains a type property (like for example type: "application/javascript" or type: "plain/text") but that's not practical as there is an endless supply of file-types out there...

Adonis K. Kakoulidis
  • 4,951
  • 6
  • 34
  • 43
  • That endless supply of file-types is how it is. You can start here, http://stackoverflow.com/questions/3146483/html5-file-api-read-as-text-and-binary, and here, http://blog.teamtreehouse.com/reading-files-using-the-html5-filereader-api. – Asons Dec 13 '15 at 17:14
  • What do you intend to do with the file after loading it? There is not much you can do with something if you don't even know what type of data it is. What I am aiming at is: *if you have a file input labeled "upload your image", then it is binary, regardless of what file user chose* – zvone Dec 13 '15 at 17:46
  • @zvone if it's binary i'd like to provide it's data-url string (`data:type, base64...`), if it's text, i'd like to just provide the text file's content. – Adonis K. Kakoulidis Dec 13 '15 at 21:51

0 Answers0