Skip to content

Instantly share code, notes, and snippets.

@majirosstefan
Created May 13, 2020 08:30
Show Gist options
  • Save majirosstefan/b1017c184d5b9a851f25c7a5853348f3 to your computer and use it in GitHub Desktop.
Save majirosstefan/b1017c184d5b9a851f25c7a5853348f3 to your computer and use it in GitHub Desktop.
@PostMapping("/savefile")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") MultipartFile file) {
String message;
try {
Path imagePath = this.rootLocation.resolve(file.getOriginalFilename())
// print path
System.out.println("Storing image to:" + resolvedPath);
Files.copy(file.getInputStream(), imagePath);
files.add(file.getOriginalFilename());
message = "Successfully uploaded!";
return ResponseEntity.status(HttpStatus.OK).body(message);
} catch (Exception e) {
System.out.println(e)
System.out.println(e.getMessage())
message = "Failed to upload!";
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment