POST Multipart Form Data using Retrofit 2.0 including image
There is a correct way of uploading a file with its name with Retrofit 2, without any hack: Define API interface: @Multipart @POST(“uploadAttachment”) Call<MyResponse> uploadAttachment(@Part MultipartBody.Part filePart); // You can add other parameters too Upload file like this: File file = // initialize file here MultipartBody.Part filePart = MultipartBody.Part.createFormData(“file”, file.getName(), RequestBody.create(MediaType.parse(“image/*”), file)); Call<MyResponse> call = … Read more