0

I was sending this via AJAX:

var formData = new FormData();
var totalfiles = document.getElementById('files').files.length;
for (var index = 0; index < totalfiles; index++) {
    formData.append("files", document.getElementById('files').files[index]);
}

And with my Spring 4 application, it should have been received by this method:

@RequestMapping(value = "/mapUploads/submit", method = RequestMethod.POST)
protected void check(HttpServletRequest request, List<MultipartFile> files)

But for some reason, Spring 4 was telling me that the bean could not be instantiated:

java.lang.NoSuchMethodException: org.springframework.web.multipart.MultipartFile

In debugging mode, it wasn't even entering the method parameter.

1 Answer 1

0

Change the method signature to this:

@RequestMapping(value = "/mapUploads/submit", method = RequestMethod.POST)
protected void check(HttpServletRequest request) {
   MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
   List<MultipartFile> files = multipartRequest.getFiles("files");
}

This problem was solved here. But in that question, OP was only using a single File in his parameter - and this is actually solvable by just adding MultipartFile in the parameter signature:

@RequestMapping(value = "/mapUploads/submit", method = RequestMethod.POST)
protected void check(HttpServletRequest request, MultipartFile>files)

This was my previous circumstance, but I ran into the bean problem when I decided to accept a list of files. I decided to create this question for those who are searching for solutions with related to a list of files

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

Comments

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.