function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tim__mTim__m 

inputFile accept attribute

What is the appropriate value for the accept attribute on the inputFile standard component? I tried "text/plain", "*.txt" and "txt" but none of that works, the browse dialog always shows all files of all types, IE and FireFox.

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

This is not honoured correctly by any of the major browsers.  The recommendation is to validate the file type server-side.

 

There's more information at:

 

http://www.cs.tut.fi/~jkorpela/forms/file.html#filter

All Answers

bob_buzzardbob_buzzard

This is not honoured correctly by any of the major browsers.  The recommendation is to validate the file type server-side.

 

There's more information at:

 

http://www.cs.tut.fi/~jkorpela/forms/file.html#filter

This was selected as the best answer
Tim__mTim__m

Yeah I just realized that the inputFile component produces the file input html tag, I don't know what I was thinking. I do have my server side validation in place so I guess I'm done. Thanks Bob!

JustinMcNally21JustinMcNally21

You could also setup Javascript validation with and onChange binding that reads the value of the input file and compares the extension via regex? To alert the user before wasting time uploading the file.