6

Say I have a form that allows users to upload multiple images, which are appended with an option to remove them if they don't want to upload that particular photo.

Is it possible to remove the value from the files object of the one that they removed (e.g. didn't want to upload)?

2

3 Answers 3

5

FileList has no API to remove entries:

https://developer.mozilla.org/en/DOM/FileList

However you can reconstruct File uploader using XHR2 and AJAX and filter in content there. This implies doing XHR2 and AJAX upload and is not suitable for traditional <form> uploads.

https://developer.mozilla.org/en/Using_files_from_web_applications

Sign up to request clarification or add additional context in comments.

Comments

1

If you are using a standard form with a set of standard file inputs then you can do it like this http://jsfiddle.net/thXre/

$(document).ready(function(){
    $('.remove').click(function(){
        $(this).closest('div').slideUp('slow', function(){$(this).remove();});
    });        
});​

and html code:

<div>
 <input type='file' name='files[]'> <img src='x.gif' class='remove'>
</div>
<div>
 <input type='file' name='files[]'> <img src='x.gif' class='remove'>
</div>
<div>
 <input type='file' name='files[]'> <img src='x.gif' class='remove'>
</div>

1 Comment

Thanks, I know how to remove the actual elements, but it's removing them from being included in the upload that I was interested in which FileList takes care of.
1

Libraries are your best bet before we get some standard API...

They are also available at https://cdnjs.com/

3 Comments

2 years later... FileList still doesn't in any way shape or form support removing entries within its API.
@bob_cobb it's a sad future =)
Future's here, still looking for a proper way to remove a file ─ doesn't seems to have one yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.