Lapsio
Lapsio

Reputation: 7084

html5 file input always accepts "unknown" file type

I'm writing web app which requires user to select csv file. However due to requiring user to have files with serveral suffixes it's quite typical to have multiple files with similar names while only one of them is .csv. the problem is accept=".csv" works only partially - it allows user to filter by csv but doesn't do it by default filtering by unknown file type

<fieldset name="inputForm">
  <legend>Input</legend>

  <label>Input file:</label>
  <input name="inputFile" type="file" accept=".csv">
</fieldset>

I also tried accept="text/csv, .csv" but it doesn't change anything.

result: screenshot

user could accidentally select for example one of .txt files or .png and that would lead to application malfunction due to malformed input file. User can select filtering by only CSV or only "unknown" but I'd prefer CSV only to be default filter because it's quite obvious nobody gonna ever switch file filtering options so realistically it's useless...

Upvotes: 7

Views: 987

Answers (1)

Tammy Shipps
Tammy Shipps

Reputation: 945

This is OS behavior and not within the scope of the browser, unfortunately. The accept attribute is mainly for ease of use on the front end and not true validation. I suggest using JavaScript or server-side validation to ensure the file selected is the right mime type desired.

Upvotes: 1

Related Questions