There is the code https://jsfiddle.net/bfzmm1hc/1 Everything looks fine but I want to delete some of the files from the set.
I have already found these:
- How to remove one specific selected file from input file control
- input type=file multiple, delete items
I know that FileList
object is readonly, so I can just copy the files to a new array. But what should I do with this new array of File
objects? I can't assign it to the files
property...
Since you cannot edit the Read Only
input.files
attribute, you must upload a form usingXMLHttpRequest
and send aFormData
object. I will also show you how to useURL.createObjectURL
to more easily get a URI from theFile
object:I found a workaround. This will not require AJAX for the request at all and the form can be sent to the server. Basically you could create an
hidden
ortext
input and set it'svalue
attribute to the base64 string created after processing the file selected.You will probably consider the idea to create multiple input file instead of input
text
orhidden
. This will not work as we can't assign a value to it.This method will include the input file in the data sent to the database and to ignore the input file you could:
disabled
attribute to the input file before serialising the form;When you want to delete a file just get the index of the element and remove the input element (text or hidden) from the DOM.
Requirements:
change
event.Pros: