@RestController public class UploadData{ @Autowired private UploadService uploadService; @PostMapping("/upload_file") protected UploadResponse uploadFile(@ModelAttribute UserUpload user, @RequestParam MultipartFile file) throws IOException,SQLException { return uploadService.uploadFile(user, file); } }
@Service public class UploadService { @Value(value = "${file.upload.dir}") String fileUploadDir; public UploadResponse uploadFile(UserUpload user, MultipartFile file) throws IOException, SQLException { Path uploadFolder = Paths.get(fileUploadDir); Path fileUploadPath = uploadFolder.resolve(file.getOriginalFilename()); Files.copy(file.getInputStream(), fileUploadPath, StandardCopyOption.REPLACE_EXISTING); String basename = FilenameUtils.getBaseName(file.getOriginalFilename()); return new UploadResponse(basename + "Uploaded Successfully"); }else { return new UploadResponse("Failed To Upload Data Set"); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)