简体   繁体   中英

With retrofit upload image using multipart form but not get the path of the file

when I am trying to upload an image using the multipart form with this code I am not getting the path of the file which I want to upload to the server.

  1. have created an interface like this and I want to upload image using multipart
 @Headers({"Content-Type: application/json;charset=UTF-8"})
    @Multipart
    @POST("api/updateprofile")
    Call<ResponseBody> uploadPhoto1(
            @Header("Authorization") String token,
            @Part("v_name") RequestBody name,
            @Part MultipartBody.Part image,
  1. when I am trying to call this api I am getting response but problem in sending file to the server.
 RequestBody namePart = RequestBody.create(MediaType.parse("text/plain"), "Narendra");
   File file = new File(filePath);
   RequestBody filePart = RequestBody.create(MediaType.parse("image/*"), file);
   MultipartBody.Part file1 = MultipartBody.Part.createFormData("v_image", file.getName(), filePart);


    APIService apiService = ApiClient.getRetrofit().create(APIService.class);
    Call<ResponseBody> Call = apiService.uploadPhoto1(token,namePart,file1);

How can I solve it?

I have Solve This Issue by my self

Just remove the header part from this interface

@Multipart
@POST("api/updateprofile")
Call<ResponseBody> uploadPhoto1(
        @Header("Authorization") String token,
        @Part("v_name") RequestBody name,
        @Part MultipartBody.Part image,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM