Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using webkitdirectory to upload a directory, is it possible to filter out certain files prior to uploading?

I'm using webkitdirectory to create an input that allows uploading an entire folder (rather than selecting individual files). I know it's non-standard and shouldn't be used in production.

I'm uploading a specific type of folder where there is one very large file that isn't needed, and many other small files. The upload takes a long time because there's a large file, but because coincidentally that's also the one file I don't actually need on the server side, I'm wondering if there's any way to filter it out prior to being uploaded?

like image 599
DeanAttali Avatar asked May 29 '18 21:05

DeanAttali


People also ask

What is webkitRelativePath?

webkitRelativePath is a read-only property that contains a string which specifies the file's path relative to the directory selected by the user in an <input> element with its webkitdirectory attribute set.

What is Webkitdirectory?

webkitdirectory is a property that reflects the webkitdirectory HTML attribute and indicates that the <input> element should let the user select directories instead of files. When a directory is selected, the directory and its entire hierarchy of contents are included in the set of selected items.

How do I upload a folder to react?

You can allow folder upload by adding these attributes empty "webkitdirectory directory" into your react-dropzone input. by using this user can't select a single file.


1 Answers

Should we assume that the large file has the same name pattern and/or content type as the files you want? Otherwise it should be possible to exclude it from the selection by using the accept attribute.

Otherwise I see 2 alternative approaches:

  • Process the list of files on submit and construct a request containing only the ones you want to send, or

  • Scan the $(myInput).files list in its change listener and copy everything you actually want to submit to another <input name="filesField" type="file" multiple style="visibility: hidden">

like image 96
DavidW Avatar answered Sep 28 '22 00:09

DavidW