Uploading a file via Multipart

suggest change

Declare your interface with Retrofit2 annotations:

public interface BackendApiClient {
    Call<RestApiDefaultResponse> uploadPhoto(@Part("file\"; filename=\"photo.jpg\" ") RequestBody photo);

Where RestApiDefaultResponse is a custom class containing the response.

Building the implementation of your API and enqueue the call:

Retrofit retrofit = new Retrofit.Builder()

BackendApiClient apiClient = retrofit.create(BackendApiClient.class);
RequestBody reqBody = RequestBody.create(MediaType.parse("image/jpeg"), photoFile);
Call<RestApiDefaultResponse> call = apiClient.uploadPhoto(reqBody);
call.enqueue(<your callback function>);

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents