未验证 提交 80d0a9d1 编写于 作者: 微笑很纯洁's avatar 微笑很纯洁 提交者: GitHub

Merge branch 'master' into master

......@@ -24,7 +24,7 @@ public class UploadController {
@PostMapping("/upload") // //new annotation since 4.3
public String singleFileUpload(@RequestParam("file") MultipartFile file,
RedirectAttributes redirectAttributes) {
RedirectAttributes redirectAttributes) {
if (file.isEmpty()) {
redirectAttributes.addFlashAttribute("message", "Please select a file to upload");
return "redirect:uploadStatus";
......@@ -33,16 +33,20 @@ public class UploadController {
try {
// Get the file and save it somewhere
byte[] bytes = file.getBytes();
Path dir = Paths.get(UPLOADED_FOLDER);
Path path = Paths.get(UPLOADED_FOLDER + file.getOriginalFilename());
// Create parent dir if not exists
if(!Files.exists(dir)) {
Files.createDirectories(dir);
}
Files.write(path, bytes);
redirectAttributes.addFlashAttribute("message",
"You successfully uploaded '" + file.getOriginalFilename() + "'");
"You successfully uploaded '" + file.getOriginalFilename() + "'");
} catch (IOException e) {
redirectAttributes.addFlashAttribute("message", "Server throw IOException");
e.printStackTrace();
}
return "redirect:/uploadStatus";
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册