I have this service in spring boot app:
@Service
public class FileStorageService {
private final Path root = Paths.get("uploads");
public void init() {
try {
Files.createDirectories(root);
} catch (IOException e) {
throw new RuntimeException("Could not initialize folder for upload!");
}
}
public ResponseEntity<?> save(MultipartFile[] files) {
if (files.length == 0) {
//return ResponseEntity.badRequest();
}
Arrays.asList(files).stream().forEach(file -> {
try {
// Get the file and save it somewhere
byte[] bytes = file.getBytes();
Path path = Paths.get(root + File.separator + file.getOriginalFilename());
Files.write(path, bytes);
} catch (IOException e) {
e.printStackTrace();
}
});
return new ResponseEntity<>(null, HttpStatus.OK);
}
}
There is some folder for saving files "uploads". And i am now wondering what is
spring.servlet.multipart.location=
setting used for. Is this just folder where raw data from request are stored before they are saved in "uploads" folder?