Home > Enterprise >  One additional duplicate file gets uploaded
One additional duplicate file gets uploaded

Time:12-07

I have my FileUpload enter image description here

Uncommenting the .peek(fileBein in my controller also shows this (twice for the duplicate file):

2022-12-07T00:23:25.971-05:00  INFO 11344 --- [nio-8080-exec-2] c.c.s.c.AppUserDocumentRestController    : Processing File 

What I am doing wrong here? Also not sure where to debug this situation. Any pointers/directions will be greatly appreciated.

CodePudding user response:

Please once go through your JS file:

function uploadMultipleFiles(files) {
    var formData = new FormData();
    for (var index = 0; index < files.length; index  ) {
        formData.append("files", files[index]);
    }
    const fileField = document.querySelector('input[type="file"]');

    //formData.append('filecusomName', 'abc123');
    formData.append('files', fileField.files[0]);

    fetch('/uploadMultipleFiles', {
        method: 'POST',
        body: formData
    })
...
...
}

The 9th line [ formData.append('files', fileField.files[0]); ] is adding duplicate of First file in FormData.

  • Related