Surjeet Singh
Surjeet Singh

Reputation: 73

By using FormData to upload multiple files along with other form values in spring mvc MultiPartHttpServlet Request object return only one file

var formData = new FormData();
formData.append("file1",file1.files[0]);
formData.append("file1",file2.files[0]);
formData.append("file1",file3.files[0]);
formData.append("file1",file4.files[0]);

On controller I am getting only one file.

Please help

Upvotes: 1

Views: 556

Answers (1)

Weafs.py
Weafs.py

Reputation: 22992

You are appending the files with the same name file1 everytime, so at the end you end up with just one file. You need to assign a unique name to each file.

var formData = new FormData();
formData.append("file1",file1.files[0]);
formData.append("file2",file2.files[0]);
formData.append("file3",file3.files[0]);
formData.append("file4",file4.files[0]);

Upvotes: 1

Related Questions