Cloudsight Api дает пустой ответ на изображение Загрузить на платформе Android

Я пытаюсь загрузить изображение на " https://api.cloudsightapi.com/image_requests", но после запроса я получаю все поля null в ответ.ie status, name, token и т. Д. Я использую модификацию 2.0.1 для совершения запроса позвоните.

Код:

RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);

MultipartBody.Part body =
MultipartBody.Part.createFormData("image_request[image]", file.getName(), requestFile);

String descriptionString = "en-US";
RequestBody description = RequestBody.create(MediaType.parse("multipart/form-data"), descriptionString);

**API CALL:**
@Multipart
    @POST("https://api.cloudsightapi.com/image_requests")
    Call<FileUploadResponse> uploadPhoto(
            @Header("Authorization") String authorisation,
            @Part("image_request[locale]") RequestBody description,
            @Part MultipartBody.Part file);

Я получаю все поля в response.body null. Пожалуйста помоги.

2 ответа

CloudSight прекратил принимать MultipartBody.Part. Поэтому мы должны отправить RequestBody, т.е. файл с именем изображения.

Я решил проблему с помощью следующих шагов:

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);

Надеюсь это поможет. Благодарю.

Загрузите файл изображения следующим образом:

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
Другие вопросы по тегам