@GetMapping("/upload")
public void upload(MultipartFile file
) throws IOException
{
String path
= "";
File file1
= new File(path
);
if (!file1
.exists()) {
file1
.mkdir();
}
file
.transferTo(new File(file1
+ "/" + file
.getOriginalFilename()));
}
@GetMapping("/download")
public void download(HttpServletResponse response
) throws IOException
{
String path
= "";
String name
= "";
response
.reset();
response
.setCharacterEncoding("UTF-8");
response
.setContentType("multipart/form-data");
response
.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder
.encode(name
, "UTF-8"));
File file
= new File(path
, name
);
FileInputStream inputStream
= new FileInputStream(file
);
ServletOutputStream outputStream
= response
.getOutputStream();
byte[] bytes
= new byte[10240000];
int index
= 0;
while ((index
= inputStream
.read(bytes
)) != -1) {
outputStream
.write(bytes
, 0, index
);
outputStream
.flush();
}
outputStream
.close();
inputStream
.close();
}