Upload a whole directory through an HTML form

后端 未结 8 2047
不思量自难忘°
不思量自难忘° 2020-11-28 12:47

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 J

8条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 13:26

    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.

提交回复
热议问题