How to Pass the image in android using Retrofit?

后端 未结 6 625
一向
一向 2021-01-17 06:03

Hello i am working on upload image file using retrofit. Can any one have idea how to pass in

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-17 06:54

    You need pass mulitypart object in retrofit:

    MultipartBody.Part carImage = null;
        if (!TextUtils.isEmpty(imagePath)) {
            File file = FileUtils.getFile(getContext(), imagePath);
            // create RequestBody instance from file
            final RequestBody requestFile =
                    RequestBody.create(MediaType.parse("multipart/form-data"), file);
            // MultipartBody.Part is used to send also the actual file name
            carImage = MultipartBody.Part.createFormData("image", file.getName(), requestFile);
        }
    

提交回复
热议问题