0

Using Retrofit to make request to a spring-data-rest instance, running into trouble sending multipart request.

Retrofit

@Multipart
@POST(URI)
void save(@Part("request[data][param][event]") Event event,
          Callback<Resource<Event>> callback);

Spring

@RequestMapping(value=URI, method=RequestMethod.POST)
public @ResponseBody HttpEntity<Event> addEvent(@RequestPart Event event) {
    ...
}

With this, I'm getting a 400 Bad Request: "Required request part 'event' is not present."

Assuming the Event object has a String name & Bitmap image, what's the proper way to handle this?

Nestor Ledon
  • 1,925
  • 2
  • 23
  • 36

1 Answers1

0

Almost had it, the save method signature should be:

@Multipart
@POST(URI)
void save(@Part("event") Event event,
          Callback<Resource<Event>> callback);
Nestor Ledon
  • 1,925
  • 2
  • 23
  • 36
  • this approach doesn`t work at me. server says:"Required MultipartFile parameter 'file' is not present","path":"/backend/newimage". Put I have a @Part("file") param, so I don`t userstand – narancs Jun 29 '15 at 16:09
  • @Karoly could you make a Gist(gist.github.com) of your serverside and client code? I'd be willing to look over it. – Nestor Ledon Jun 29 '15 at 19:11
  • Please find my question here:http://stackoverflow.com/questions/31121212/retrofit-and-multipart-image-uploading-with-http-400/31121642#31121642 – narancs Jun 29 '15 at 22:13