How to retain file input value after drag and drop?

241 Views Asked by At

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

There are 1 best solutions below

2
Kevin On

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();