问题描述
<form th:action="@{/upload}" method="post" enctype="multipart/form-data">
<input type="file" name="files">
<input type="submit" value="Upload Files" accept="image/png,image/jpeg"></input>
</form>
这是我的控制器:
private final String UPLOAD_DIR = "./uploads/";
@PostMapping("/upload")
public String upload(@RequestParam("files") multipartfile file,RedirectAttributes attributes) {
if(file.isEmpty()) {
attributes.addFlashAttribute("message","Please select a file to upload.");
return "redirect:/";
}
String fileName = StringUtils.cleanPath(file.getoriginalFilename());
try {
Path path = Paths.get(UPLOAD_DIR,fileName);
Files.copy(file.getInputStream(),path,StandardcopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printstacktrace();
}
attributes.addFlashAttribute("message","You successfully uploaded " + fileName + '!');
return "redirect:/";
}
一切都可以在localhost(windows)上正常运行,但是我的问题是它在服务器(linux)上不起作用,因为我得到了一个例外: “ java.nio.file.filesystemexception:./uploads/file.png:只读文件系统”“ uploads”文件夹具有所有权限,请帮助,我不再有想法。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)