I send the file to the server using Retrofit2 , I use the POST method to send the file, the POST method takes two parameters "file" and "shared-with":
@Multipart @POST("im-file") Call<RequestBody> sendFile(@Part MultipartBody.Part file, @Part("shared-with") String sharedWith); Method to send files to server:
private void testSendFile(){ File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + "gallery.png"); RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file); MultipartBody.Part body = MultipartBody.Part.createFormData("picture", file.getName(), requestFile); Call<RequestBody> call = BaseApi.getInstance().service.sendFile(body, "bob"); call.enqueue(new Callback<RequestBody>() { @Override public void onResponse(Call<RequestBody> call, Response<RequestBody> response) { Log.e("Response: ", String.valueOf(response)); Log.e("Response headers in send file: ", String.valueOf(response.headers())); Log.e("Response code in send file: ", String.valueOf(response.code())); } @Override public void onFailure(Call<RequestBody> call, Throwable t) { Log.e("File send error: ", t); } }); } I get 400 error, "message":"Required request part 'file' is not present","path":"/" .
When testing a request in Postman, everything works:
What could be wrong?

fileobject initialized normally? - post_zeew