I am trying to upload files using the form:
<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>
and this is my controller:
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:/";
}
everything works fine on localhost (windows) but my problem is that it doesn't work on the server (linux) because I get an exception: "java.nio.file.FileSystemException: ./uploads/file.png: Read-only file system" the "uploads" folder has all permissions, please help, I have no ideas anymore.