Hello i am working on upload image file using retrofit. Can any one have idea how to pass in
/* Create interface like below. */
public interface uploadWishImage {
@Multipart
@POST("upload/image")
Call postImage(@Part MultipartBody.Part image, @Part("name") RequestBody name);
}
/* image upload code */
File file = new File("here your file path");
RequestBody reqFile = RequestBody.create(MediaType.parse("image/*"), file);
MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), reqFile);
RequestBody name = RequestBody.create(MediaType.parse("text/plain"), "file");
uploadWishImage postService = RetrofitApi.makeNetworkRequestWithHeaders(AddWish.this).create(uploadWishImage.class);
Call call = postService.postImage(body, name);
call.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
// somethings to do with reponse
}
@Override
public void onFailure(Call call, Throwable t) {
// Log error here since request failed
}
});