我需要将 4 个图像作为文件发送到服务器(我不能转换为位图或字符串),服务器应该仅将数组 (files[]) 中的所有 4 个文件作为数组接收。我怎样才能在 android 中使用 RETROFIT 实现这一点
请参阅下文了解所需的服务器上传
D/OkHttp: pics=[image1,image2,image3,image4]&txt=&pic=true&type=img
最佳答案
要在改造 2 中上传图片,请尝试使用此代码
像这样创建Api接口(interface):
@Multipart
@POST("uploadAttachment")
Call<MyResponse> uploadAttachment(@Part MultipartBody.Part filePart);
然后像这样上传文件:
File file = // initialize file here
MultipartBody.Part filePart = MultipartBody.Part.createFormData("pics", file.getName(), RequestBody.create(MediaType.parse("image/*"), file));
Call<MyResponse> call = api.uploadAttachment(filePart);
关于java - 安卓 : Send Multiple images as file to server using retrofit in an array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41761487/