0

Here is the code I use to drag and drop multiple files:

document.getElementById('file-input').files = e.dataTransfer.files;

This works, but how can I retain the old value after a second drag and drop?

I tried combining both arrays but the FileList is read only. I could try:

let newFile = new File()

But I cannot not find any documentation on how to properly to do so.

1 Answers1

0

To save all your files (old and new), you need a server because you cannot save in the browser (front-end). If you want to do this temporarily, then you must avoid page refreshes, one solution is to add event.preventDefault();

Kevin
  • 85
  • 7
  • 1
    Thanks, I am already using `event.preventDefault();` and I am not refreshing the page. During the drag and drop, the files are saved to input[File] via JavaScript. – Matt Richardson Nov 11 '22 at 04:03
  • What you can do is use the `localStorage` and you can see useful information here: “https://stackoverflow.com/questions/19119040/how-do-i-save-and-restore-a-file-object-in-local-storage” Although my recommendation is to use a server. – Kevin Nov 13 '22 at 11:46