Explorar el Código

Take files from preexisting file input

Renée Kooi hace 6 años
padre
commit
4fb7226ede
Se han modificado 1 ficheros con 9 adiciones y 1 borrados
  1. 9 1
      packages/@uppy/transloadit-preset/src/AttachFileInputs.js

+ 9 - 1
packages/@uppy/transloadit-preset/src/AttachFileInputs.js

@@ -17,7 +17,11 @@ class AttachFileInputs extends Plugin {
   }
 
   handleChange (event) {
-    const files = toArray(event.target.files)
+    this.addFiles(event.target)
+  }
+
+  addFiles (input) {
+    const files = toArray(input.files)
     files.forEach((file) => {
       try {
         this.uppy.addFile({
@@ -55,6 +59,10 @@ class AttachFileInputs extends Plugin {
       if (!input.hasAttribute('accept') && restrictions.allowedFileTypes) {
         input.setAttribute('accept', restrictions.allowedFileTypes.join(','))
       }
+
+      // Check if this input already contains files (eg. user selected them before Uppy loaded,
+      // or the page was refreshed and the browser kept files selected)
+      this.addFiles(input)
     })
   }