Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

351
Views
jquery Add file object to FileList object

I'm trying to create simple image uploader for my website, but I have one problem. When I want to add my new image to previous selected image can't hold old selected images (because new FileList object created) and then send them all to my controller and my problem back to ,adding old 'files object' to new 'FileList Objects'. html:

<div id="filediv">
    <input type="file" id="file" name="files[]" multiple="multiple" />
</div>

script:

window.filesToUpload = [];
window.tmp = [];
$("#file").on('change', function () {
    "use strict";

    if (window.filesToUpload.length > 0) {
        $.each(window.tmp, function (i, img) {

i want to add old file object to new FileList Object HERE

        });
    }

    if (this.files.length >= 1) {
        $("[id^=previewImg]").remove();
        $.each(this.files, function (i, img) {
            window.tmp.push(img);

            var reader = new FileReader(),
                newElement = $("<div id='previewImg" + i + "' class='abcd'><img /></div>"),
                preview = newElement.find("img");

            reader.onloadend = function () {
                preview.attr("src", reader.result);
                preview.attr("alt", img.name);
            };

            try {
                window.filesToUpload.push(document.getElementById("file").files[i]);
            } catch (e) {
                console.log(e.message);
            }

            if (img) {
                reader.readAsDataURL(img);
            } else {
                preview.src = "";
            }


            newElement.appendTo("#filediv");
        });
    }
});
about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!