Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FileList constructor #24

Open
dmoagx opened this issue Oct 21, 2015 · 3 comments
Open

Add FileList constructor #24

dmoagx opened this issue Oct 21, 2015 · 3 comments

Comments

@dmoagx
Copy link

dmoagx commented Oct 21, 2015

Split out from https://www.w3.org/Bugs/Public/show_bug.cgi?id=17125 :

The

<input type="file" name="something" />

element has always been readonly (you can't change value) for security purposes.
That makes sense as a string could always be manipulated by JS.

The File object on the other hand should be "safe", as in

  • Only the browser can create one on user request (ie. by file input or drag and drop)
  • JS cannot change it in any way

So it should not be a security issue to allow assignment to a file input.
For example:

<input type="file" name="something[]" onchange="splitFiles();" id="in1" multiple="multiple" />
function splitFiles() {
  var in = document.getElementById('in1');
  //create single inputs
  for(var i=0;i<in.files.length;i++) {
        var newEl = document.createElement('input');
        newEl.name = "something[]";
        newEl.id = '...';
        newEl.type = "file";
        newEl.value = in.files[i]; // <-- assignment of file object
        document.appendChild(newEl); //add for upload
        //create some UI to remove this input
        //...
    }
    //remove the multi-input
    in.parent.removeChild(in);
}

This code would split a multi-file-input back to multiple single-file inputs (that way applications with a legacy backend that only supports the classical way could also support multi-file-inputs).

Another use would be with File objects obtained by drag and drop.
Right now those require XHR to upload. Allowing to make them a selection of a file input could simplify some situations as well as provide richer UI (when showing a traditional file input together with a drop area those would stay in sync).

@vsesh
Copy link
Contributor

vsesh commented Oct 24, 2016

#19

@inexorabletash
Copy link
Member

I think we can close this c/o whatwg/html#2861 being resolved?

@annevk
Copy link
Member

annevk commented Dec 5, 2017

The first use case for legacy backends can't be done until whatwg/html#3269 is resolved somehow. We could use this as the File API side issue for that, as it'll need to change here eventually.

@annevk annevk changed the title Make input[type=file] assignable for File objects Add FileList constructor Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants