附件上传时,火狐等浏览器可以成功上传,但是谷歌浏览器存在上传失败的情况。
目前发现的问题,59版本以上,67版本以下存在可以上传docx,但是不可以上传doc;
xls可以上传,但是xlsx不可以上传的情况。目前可以知道的是67版本支持doc和docx上传
附一个简单的附件上传代码
public class FileUtil {
public static void test (byte[] file, String filePath, String fileName) throws Exception {
File targetFile = new File(filePath);
if(!targetFile.exists()){
targetFile.mkdirs();
}
FileOutputStream out = new FileOutputStream(filePath+fileName);
out.write(file);
out.flush();
out.close();
}
}
@RequestMapping(value="/test", method = RequestMethod.POST)
public @ResponseBody String test (@RequestParam("file") MultipartFile file,HttpServletRequest request) {
String contentType = file.getContentType();
String fileName = file.getOriginalFilename();
String filePath = "D:\\Program Files\\test"; //这里举个例子设置的绝对路径,也可以放相对路径
try {
FileUtil.uploadFile(file.getBytes(),filePath , fileName);
} catch (Exception e) {
// TODO: handle exception
}
//返回json信息
return "success";
}