I have problem with sending multipartRequest to server.
RequestBody file = RequestBody.create(MediaType.parse("application/json"), myFile);
return apiService.updateProfile2(token, file);
@Multipart
@POST("/profile/update")
Call<RegistrationResponse> updateProfile2(@Header(value = "X-AUTH-TOKEN") String toke, @Part(value = "json") RequestBody json);
problem:
request body is empty, when it come to server
Uploading files with Retorfit 2 and Multipart
http://www.codejava.net/java-se/networking/upload-files-by-sending-multipart-request-programmatically Here is a good article with code that sends multipart. This worked for me.
MultipartUtility multipart = new MultipartUtility(requestURL, charset);
multipart.addHeaderField("User-Agent", "CodeJava");
multipart.addHeaderField("Test-Header", "Header-Value");
multipart.addFormField("description", "Cool Pictures");
multipart.addFormField("keywords", "Java,upload,Spring");
multipart.addFilePart("fileUpload", uploadFile1);
multipart.addFilePart("fileUpload", uploadFile2);
List<String> response = multipart.finish();
System.out.println("SERVER REPLIED:");
for (String line : response) {
System.out.println(line);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With