How do I upload the content of a folder using JavaScript (client side)? The FileSystem API has not been adopted by browsers other than Chrome; I only get a File item with the name of the folder.
It should be possible, because Google Drive allows to drop a folder and all the content (folders and files) will be uploaded automatically.
js fs core module to get all files in the directory, we can use following fsmethods. fs. readdir (path, callbackFunction) — This method will read all files in the directory. You need to pass directory path as the first argument and in the second argument, you can any callback function.
Upload files & folders On your computer, go to drive.google.com. File Upload or Folder Upload. Choose the file or folder you want to upload.
You can actually upload directories in all latest versions of Chrome, Firefox and Microsoft Edge. There are numerous working examples available to look at.
Here is a good, working example that I've previously used in a project
Quarklemotion Html5FileSelector
In addition, Dropzone JS also supports directory uploads as well and it works in Chrome, FF and Edge. I've just transitioned to using this in my own project.
Dropzone JS
These solutions recursively read the directory entries and list all of the files including their relative paths. If you want to rebuild the folder structure when uploading you will have to implement that using the relative paths and the appropriate algorithm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With