我基本上是一个Java开发人员,只有Android开发的基本信息。我已经开发了一个web端点,它可以接受一个文件和一些其他参数。java代码是
@RequestMapping(path = "/api/beneficiary/initial/inspection/upload", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody String uploadInitialInspectionPhoto(@RequestParam(value = "uploadImg") MultipartFile file,
@RequestParam("hdId") Long hdId, @RequestParam("toRegId") String toRegId,
@RequestParam(value = "remark", required = false) String remark,
@RequestParam(value="latitude")String latitude,
@RequestParam(value="longitude")String longitude) {
//.... Method Code
}我的Android开发人员说,在异步后台线程上上传10个文件需要10分钟,因为它必须点击URL 10次。她建议我将API改为接受ArrayList。即,将接口更改为
@RequestMapping(path = "/api/beneficiary/initial/inspection/upload", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody String uploadInitialInspectionPhoto(@RequestParam(value = "uploadImg") MultipartFile[] files,
@RequestParam("hdId") Long[] hdIds, @RequestParam("toRegId") String[] toRegIds,
@RequestParam(value = "remark", required = false) String[] remarks,
@RequestParam(value="latitude")String[] latitudes,
@RequestParam(value="longitude")String[] longitudes) {
for (int idx = 0; idx < hdIds.length; idx++)
{
//... Same code as in current method
officerSvc.save(.....)
}
} 注意复数形式和[]
我的基本问题是:是否建议更改api以接受ArrayList/Array而不是单个实例,以提高上传的性能并发挥其优点?事实还是虚构?
发布于 2019-02-25 14:47:30
是的,它将节省在客户端和服务器之间建立连接的时间。但不是很多,可能是1-2秒。
https://stackoverflow.com/questions/54860765
复制相似问题