Cloudsight Api对Android平台上的图片上传提供空响应 [英] Cloudsight Api provides empty response on image Upload on Android platform
问题描述
我正在尝试在" https://api.cloudsightapi.com/image_requests上上传图像" 但是在请求调用之后,我将所有字段都设为null,即状态,名称,令牌等.我正在使用翻新版2.0.1进行请求调用.
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,name,token etc. I am using retrofit 2.0.1 for making request call.
代码:
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中.请帮忙.
I am getting all the fields into response.body null. Please help.
推荐答案
CloudSight停止接受MultipartBody.Part,因此我们必须发送具有图像名称的RequestBody即文件.
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.
这篇关于Cloudsight Api对Android平台上的图片上传提供空响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!