In my code I have to make a MultipartForm-Data PUT request to update an object in the server, it ought to be Multipart as it is possible the user will send an image together with the data.
In order to do that, I am currently using Retrofit since it's a library I'm decently used to and it's working to send images to the server.
However, things have changed server-side and now one of the parameters that must be sent is:
{"step":
{"type":"begin"}
}
However that's been proving to be surprisingly hard to do.
Things I have tried include passing it as a MultipartTypedOutput, a hand-typed String and a JSONObject converted to String, all of which gave me:
retrofit.RetrofitError: 400 Bad Request
The URL being used is correct, I've double checked with the person who maintains the server and it is reaching the server, but with an incorrect "step" object.
I've also tried passing it as NameValuePair, Map and HashMap, all of which gave me:
retrofit.RetrofitError: Part body must not be null.
@FieldPart which looks to be perfect for this isn't compatible with Multipart, so is there a way to do this with Retrofit at all?
My current PUT method is as such:
@Headers({
"Connection: Keep-Alive",
"Accept-Language: en-US"
})
@Multipart
@PUT("/0.1/user/{id}")
String updateUser(@Path("id") String userId, @Part("step") Map<String,String> type);
Where the Map type has been changed to all the types I mentioned before.
I still don't understand what the issue is, as the "Part body must not be null" occurred even when trying out what Ankush mentioned.
Either way, I spoke to a few friends and a few contact expansions later, I got the following solution:
@Headers({
"Connection: Keep-Alive",
"Accept-Language: en-US"
})
@Multipart
@PUT("/0.1/user/{id}")
String updateUser(@Path("id") String userId, @Part("step[type]") String type);
As far as I could find, this isn't mentioned anywhere in retrofit's documentation, but it does work.