I am using Retrofit 2.0 for image upload to server in Android. Following is the interface code.
@Headers("Content-Type: multipart/form-data; boundary=MyMediaFormBoundary")
@Multipart
@POST("api/media/upload/v1")
Call<MyResponse> uploadMedia(@Header("authToken") String authToken,
@Part("media_file\"; filename=\"media_file.jpg\" ") RequestBody filePart,
@Part("media_format") RequestBody format,
@Part("media_library_id") RequestBody noteId,
@Part("media_title") RequestBody title);
Here is my code to create request body params
File file = new File(mediaFileUri.getPath());
RequestBody fbody = RequestBody.create(MediaType.parse("image/*"), file);
RequestBody formatBody = RequestBody.create(MediaType.parse("text/plain"), format);
RequestBody titleBody = RequestBody.create(MediaType.parse("text/plain"), title);
RequestBody idBody = RequestBody.create(MediaType.parse("text/plain"), id + "");
When I call my interface method with above parameters, I am getting error 'steam ended unexpectedly' and I am wondering what exactly I am doing wrong.
I also tried using MultipartBody.Part object of retrofit in above interface but still same result.
Following are the links which I used for reference: first link second link
Note: I doubt it is related to bad request but I am not getting much help from backend team and it is working on iOS. The only info I have is server side is fetching media file against key 'media_file' but I am wondering where to use it.