直接上图,亲测有效
1.下载、预览

@GetMapping("/download")
public void download(@RequestParam("online")Boolean online, HttpServletResponse response) throws IOException {
FileInputStream fileInputStream = new FileInputStream("D://文件服务器//测试//ccc.pdf");
if(online){ //下载
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode( "计划书.pdf", "UTF-8"));
}
StreamUtils.copy(fileInputStream,response.getOutputStream());
}
2.文件上传
@PostMapping("/upload")
public String upload(@RequestBody String base64) {
try {
ByteArrayInputStream imgIptStream = new ByteArrayInputStream(Base64.decodeBase64(base64));
File signFile = File.createTempFile("sign", ".png");
FileCopyUtils.copy(imgIptStream, new FileOutputStream(signFile));
//保存signFile到文件服务器
String fileId = uploadFileServerUtil.uploadFile(signFile);
} catch (Exception e) {
return "文件上传发生异常";
}
return "文件上传成功";
}
1520

被折叠的 条评论
为什么被折叠?



