0

I need to send a html form to a springboot application. The Form is manipulated before submitting, so I use an ajax request to submit it manually:

$.ajax({
    method: 'POST',
    processData: false,
    contentType: false,
    url: form_submit_url,
    data: formData
});

I checked formData to be sure that it contains all form values including files.

The following code works for all form items except files. Inspecting functionRequest shows that file parameters are missing.

@PostMapping(
    value = "form_submit_url",
    consumes = {
        MediaType.MULTIPART_FORM_DATA_VALUE
    },
    produces = MediaType.APPLICATION_JSON_VALUE
)
@ResponseStatus(HttpStatus.ACCEPTED)
public FunctionResult executeFunction(
    final @RequestParam MultiValueMap<String, Object> functionRequest
) {
    return null;
}

MultiValueMap is used since received parameters may vary.

Is it possible to reiceive files along with other parameters when using MultiValueMap? Otherwise is there an alternative?

anste
  • 100
  • 3
  • 11
  • you should not use @RequestParam if your controller catches POST requests, as POST requests sends data in a body payload – Aayush Rohatgi Sep 05 '18 at 08:42
  • Please check this link: https://stackoverflow.com/questions/47457382/can-i-use-requestparam-annotation-for-a-post-request – Aayush Rohatgi Sep 05 '18 at 08:43
  • I already tried to use @RequestBody but it results in an error: "Content type 'multipart/form-data;boundary=----WebKitFormBoundaryiABkW6WBEvdbrXZZ;charset=UTF-8' not supported". Your link suggests to create a DTO, but that's not possible since I don't know the parameters. – anste Sep 05 '18 at 09:16

0 Answers0