0

I'm using cycero's excellent additions to Sebastian Tschan's jQuery File upload to submit the filename at the same time.

// Storing the file name in the queue
var fileName = "";

// On file add assigning the name of that file to the variable to pass to the web service
    $('#fileupload').bind('fileuploadadd', function (e, data) {
        $.each(data.files, function (index, file) {
            fileName = file.name;
        });
    });

// On file upload submit - assigning the file name value to the form data
    $('#fileupload').bind('fileuploadsubmit', function (e, data) {
        data.formData = {"imagefilename" : fileName};
    });

Unfortunately when I do a multi-file upload it posts the same filename for all files rather than a filename each.

How do I create a filename field/argument for each file?

https://dev.over60travel.com/sandbox/jQuery-File-Upload/index.html

2
  • How you declared 'fileName' variable is a common instance. So it will keep overwriting with the latest value when you first loop through. Try using an array and pushing the filenames and retrieve on submit. Commented Nov 5, 2018 at 5:45
  • Yeah, I guess that code was for a simpler form. Unless I'm mistaken, the form is built with javascript and then when you opt to Upload All it loops through the form and repeatedly invokes the upload handler. I can't really work out where the form is built and how to add a filename array element to it though. Commented Nov 5, 2018 at 10:03

0

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.