1.我做的这个项目,后台下载总是报解析失败错误,或者下载百分比问题。
百分比问题是由于Content-Length不正确导致的,必须要求后台传正确的apk大小。
Controll 代码
@RequestMapping(value = "/downloadApp", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "下载文件", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ResponseBody
public Object download(@ApiParam(value = "应用App主键ID", name = "appId")String appId,HttpServletResponse response) throws Exception {
try {
// 清空response
response.reset();
// 设置response的Header
response.setContentType("application/vnd.android.package-archive;");
response.setHeader("Content-disposition", "attachment; filename=" + new String(apkInfoVO.getFileName().getBytes("utf-8"), "ISO8859-1"));
response.setHeader("Content-Length", String.valueOf(getFileLength(apkInfo.getFilePath())));
Outp