3

I want to send a POST request from my service to a SpringBoot @RestController. I have a bunch of string parameters that I am sending, but I also have a FormData parameter which is an image (picture argument). If I do it like this:

  public createEvent(name, description, fromDate, toDate, userId, picture){
      this.http.post(this.baseUrl + 'create',
          {
              name: name,
              description: description,
              fromYear: fromDate['year'],
              fromMonth: fromDate['month'],
              fromDay: fromDate['day'],
              toYear: toDate['year'],
              toMonth: toDate['month'],
              toDay: toDate['day'],
              userId: userId,
              picture: picture
          }).subscribe();
  }

And my Controller method looks like this:

@PostMapping(value = "/create")
    public void createEvent(@RequestBody Map map){}  

The map looks like this:
enter image description here

and I can't get the file.
I can send the FormData as a single parameter in a post request and receive it as a Multipart file in my controller without any problems, but is it possible to send it in the same request with the other parameters?

1 Answer 1

1

Apparently, you can append all of the parameters in the FormData object, and access them through @RequestParam in the controller.

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.