Reputation: 1964
I need to restrict users to upload certain type of files, how should I do that? I know that I can receive the file and check the ContentType variable but I need to change the way their browser looks for files.
Lets say the required file type is csv, when they click on upload and the window will be opened to look for files in their file system, they should only be able to see files with csv extension. In this way they are forced to upload CSV files as no other file is visible to be selected.
<s:form id="uploadCSV" method="POST" action="add" enctype="multipart/form-data">
<s:file name="csv" label="Upload File"/>
<s:submit/>
</s:form>
Upvotes: 2
Views: 6394
Reputation: 7184
The HTML5 standard specifies an accept
attribute for input elements. It allows you to specify the MIME type and the extension and the standard recommends specifying both, so your code should look like this:
<input type="file" accept=".csv,text/csv"></input>
HTML4 does not allow specifying extensions, so you can only use the MIME type:
<input type="file" accept="text/csv"></input>
Upvotes: 1