@PostMapping("/upload") public String uploadFile(@RequestParam("file") MultipartFile file) { // Check if the file is empty if (file.isEmpty()) { return"文件为空"; }
try { // Ensure the upload directory exists FileuploadDir=newFile(UPLOAD_DIR); if (!uploadDir.exists()) { uploadDir.mkdirs(); }
// Save the file to the specified directory FiletargetFile=newFile(UPLOAD_DIR + File.separator + file.getOriginalFilename()); file.transferTo(targetFile);
@PostMapping("/upload") public String uploadFile(@RequestParam("file") MultipartFile file) { // Check if the file is empty if (file.isEmpty()) { return"文件为空"; }
try { // Ensure the upload directory exists FileuploadDir=newFile(UPLOAD_DIR); if (!uploadDir.exists()) { uploadDir.mkdirs(); }
// Save the file to the specified directory FiletargetFile=newFile(UPLOAD_DIR + File.separator + file.getOriginalFilename()); try (FileOutPutStreamfos=newFileOutputStream(targetFile)) { fos.write(file.getBytes()); }