Android-Retrofit多文件上传出错
创始人
2024-08-19 20:30:09
0
  1. 借助 MultipartBody.Part 和 RequestBody 类型参数进行多文件上传:

MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM); for (int i = 0; i < files.size(); i++) { File file = new File(files.get(i).getPath()); RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); builder.addFormDataPart("file_name" + i, file.getName(), requestBody); } MultipartBody multipartBody = builder.build(); Call call = api.uploadFiles(multipartBody);

  1. 在 Retrofit 接口声明的方法中使用 @Part List 类型的参数,用于支持多个文件上传:

@Multipart @POST("upload/files") Call uploadFiles(@Part MultipartBody.Part file1, @Part MultipartBody.Part file2);

List parts = new ArrayList<>(); for (int i = 0; i < files.size(); i++) { File file = new File(files.get(i).getPath()); RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); MultipartBody.Part part = MultipartBody.Part.createFormData("file_name" + i, file.getName(), requestBody); parts.add(part); } Call call = api.uploadFiles(parts);

相关内容

热门资讯

智星德州插件2024最新版!w... 智星德州插件2024最新版!wepoker破解器(透视)技巧-确实详细是真的挂;1、智星德州插件20...
wepoker网页版透视方法!... wepoker网页版透视方法!We poker辅助器下载(透视)脚本-真是推荐存在有挂wepoker...
wepoker透视方法!哈糖大... wepoker透视方法!哈糖大菠萝软件下载(透视)app-竟然必备是真的挂1、哈糖大菠萝软件下载公共...
约局吧开挂神器是真的吗!wep... 约局吧开挂神器是真的吗!wepoker免费透视脚本(透视)攻略-确实揭露真的是有挂1、每一步都需要思...
hhpoker有透视的吗!we... hhpoker有透视的吗!wejoker辅助脚本(透视)方法-确实必备真的是有挂1、操作简单,无需h...
wepoker有没有挂!hhp... wepoker有没有挂!hhpoker德州牛仔视频(透视)软件-切实揭幕真的有挂1、许多玩家不知道h...
epoker有透视吗!wpk德... epoker有透视吗!wpk德州局透视(透视)神器-总是普及真的有挂1、操作简单,无需epoker有...
德州私人局怎么透视!pokem... 德州私人局怎么透视!pokemmo脚本(透视)器-其实详情是有挂1、不需要AI权限,帮助你快速的进行...
wepoker透视方法!xpo... wepoker透视方法!xpoker辅助神器(透视)挂-确实推荐存在有挂1、上手简单,内置详细流程视...
hhpoker透视工具!智星菠... hhpoker透视工具!智星菠萝可以辅助吗(透视)工具-一直透视真的有挂一、智星菠萝可以辅助吗游戏安...