Created
May 13, 2020 08:30
-
-
Save majirosstefan/b1017c184d5b9a851f25c7a5853348f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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