Upload a whole directory through an HTML form

Viewed 50216

Is it possible to upload a folder with a file input in the browser?

I searched and found out that this might be a browser limitation and that I might need to use a Java Applet or Flash.

8 Answers

in case you use dropzone: dropzone scans files inside directory droped and correspondent sub directorys making a request to backend per file. this file original fullpath is catched

https://www.dropzonejs.com/#event-sending

PD: used lodash (_.without) for the example:

sendingEvent(file, xhr, formData){

    if (file.fullPath) { //file.fullPath only exist if file is inside a directory
        var directoryStructure = _.without(file.fullPath.split("/"), file.name);
        formData.append('directory-structure', directoryStructure.join(",") );
    }
}

you has received in request:

  • directory-structure : path
  • file: binary

now you can work with this folder name in your backend. dropzone can make multiple uploads separatly without issues and works fine for your use case.

Related