我正在尝试上传图像"https://api.cloudsightapi.com/image_requests https://api.cloudsightapi.com/image_requests"但在请求调用之后,我将所有字段都设为 null 到响应中。即状态、名称、令牌等。我正在使用 Retrofit 2.0.1 进行请求调用。
Code:
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 中。请帮忙。
像这样上传图像文件:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)