anon
anon

Reputation:

Spring 3/Square Retrofit - MultipartParams but no MultipartFiles

I have the following controller set up:

@PreAuthorize("hasAuthority('ROLE_USER')")
@RequestMapping(value = "/me/avatar", method = RequestMethod.POST)
public @ResponseBody boolean setAvatar(Principal principal, MultipartHttpServletRequest request) {

    String username = ((User) ((OAuth2Authentication) principal).getPrincipal()).getUsername();

    MultipartFile file = request.getFile("avatar");
    return Boolean.TRUE;
}

And when I use Square Retrofit to POST to this controller:

@Multipart
@POST("/user/me/avatar?access_token={access_token}")
void uploadAvatar(@Name("access_token") String accessToken, @Name("avatar") TypedFile image, retrofit.http.Callback<Boolean> callback);

I get a MultipartHttpServletRequest which has the "avatar" parameter, with the proper file name and everything, but no multipart files.

What am I doing wrong that would cause me to get MultipartParams but no MultipartFiles? I've tried various other TypedOutput formats, but I get the same result. If I hit the same controller from Postman (a Chrome plugin) everything works as expected, leading me to think it's a bug in Retrofit?

Upvotes: 1

Views: 1364

Answers (1)

anon
anon

Reputation:

This was due to a bug in Retrofit, which has been fixed as of today. The above code now works to upload a file from Retrofit to a Spring based api server.

Upvotes: 1

Related Questions