如何在android改造中发布图像和数据 [英] How to Post image and data in android retrofit
本文介绍了如何在android改造中发布图像和数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使用改造发布数据和图像.你能帮帮我吗
I am unable to post data and image using retrofit. can u please help me
@Multipart
@POST("click_and_post")
Call<ResponseBody> clicPost(
@Part ("click_and_post[image]") RequestBody file,
@Part ("click_and_post[category_id]") String category_id,
@Part ("click_and_post[brand_id]") String brand_id,
@Part ("click_and_post[location]") String location);
博主我无法发送数据,你能帮我吗
POst man I am unable to send data can u help me
推荐答案
这就是你应该如何实现这个 api
This is how you should implement this api
int size = youImagePathList.size();
MultipartBody.Part[] multipartImageList = new MultipartBody.Part[size];
if(size > 0) {
for (int i = 0; i < size; i++) {
File file = new File(notificationItemList.get(i).getImageEncoded());
RequestBody surveyBody = RequestBody.create(MediaType.parse("image/*"), file);
multipartImageList[i] = MultipartBody.Part.createFormData(""click_and_post[image]"", file.getName(), surveyBody);
}
}
RequestBody category_id = RequestBody.create(MediaType.parse("multipart/form-data"), StringCategoryID);
RequestBody brand_id = RequestBody.create(MediaType.parse("multipart/form-data"), StringBrandId);
RequestBody location = RequestBody.create(MediaType.parse("multipart/form-data"), StringLocation);
@Multipart
@POST("click_and_post")
Call<ResponseBody> clicPost(
@Header("Authorization") String authorization, // if there is headers
@Part MultipartBody.Part[] multipartImageList,
@Part("click_and_post[category_id]") RequestBody category_id,
@Part("click_and_post[brand_id]") RequestBody brand_id,
@Part("click_and_post[location]") RequestBody location);
这篇关于如何在android改造中发布图像和数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文