I was previously using apache to preform file upload:
FileBody fileBody = new FileBody(new File(path), mimeType); FormBodyPart formBodyPart = new FormBodyPart("partName", fileBody); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart(formBodyPart); ... That would successfully upload the file with the part name of 'partName'
Switching to retrofit:
public interface UploadService { @Multipart @PUT("/somepath/{id}/upload") Call<ResponseBody> upload(@Path("id") String id, @Part("partName") RequestBody file); } var id = 123; UploadService service = retrofit.create(UploadService.class); File file = new File(path); RequestBody requestBody = RequestBody.create(MediaType.parse(mimeType), file); Response<ResponseBody> response = service.upload(id, requestBody).execute(); The partName of the request is not set. What am I doing wrong?
Headers.of("Content-Disposition", "form-data; name=\"file\"; filename=\"ic_launcher.png\"")because with my web service (Asp.Net Web API), when android client did not setfilenamehere, the web service did not think it is a multipart request