Cloudsight Api provides empty response on image Upload on Android platform

前端 未结 2 1763
误落风尘
误落风尘 2021-01-27 17:17

I am trying to upload an image on \"https://api.cloudsightapi.com/image_requests\" but after request call i am getting all the fields null into response .i.e status,nam

相关标签:
2条回答
  • 2021-01-27 18:00

    Upload image file like this:

    File file = // initialize file here
    
    MultipartBody.Part filePart = MultipartBody.Part.createFormData("file", file.getName(), RequestBody.create(MediaType.parse("image/*"), file));
    
    Call<MyResponse> call = api.uploadPhoto(filePart);//u can send other parameters along with the filePart depending upon ur method signature
    
    0 讨论(0)
  • 2021-01-27 18:16

    CloudSight stopped accepting MultipartBody.Part So we have to send RequestBody i.e file with image name.

    I have solved the issue with following steps:

    RequestBody requestFile = RequestBody.create(MediaType.parse("image*/"), file);
    
    String descriptionString = "en-US";
    
    RequestBody description = RequestBody.create(MediaType.parse("multipart/form-data"), descriptionString);
    
    apiInterface.uploadPhoto("CloudSight key",description, requestFile);
    
    
    In retrofit api call:
    
    @Multipart
        @POST("https://api.cloudsightapi.com/image_requests")
        Call<FileUploadResponse> uploadPhoto(
                @Header("Authorization") String authorisation,
                @Part("image_request[locale]") RequestBody description,
                @Part("image_request[image]\"; filename=\"file.jpg\" " ) RequestBody file);
    

    Hope This helps. Thanks.

    0 讨论(0)
提交回复
热议问题