java - 安卓 : Send Multiple images as file to server using retrofit in an array

标签 java android xml

我需要将 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/

相关文章:

java - Java中向类属性传递参数

java - 将值传递给另一个jsp

android - 在挂起功能可能失败的情况下,结合挂起功能和流功能的最佳方法是什么?

java - eclipse插件开发: how to open a custom editor from a cnf (on double click).

java - 请求的资源不可用。 (jsp、servlet)

java - NFC (Android Studio) - 如何通过单击按钮启用/禁用 NFC

android - 如何在 Linux 中更改 AVD 管理器的默认列表路径?

xml - Eclipsie 在rebel.xml 中显示 cvc-complex 类型错误

c++ - 验证 Unicode 字符串并在 Unicode 无效时转义 (C/C++)

c# - 使用 JSON.Net 自定义 JSON 到 XML 的转换