Springboot上传文件

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;

@RestController
public class UploadController {

    @PostMapping("/upload")
    public String upload(MultipartFile file) {
        if (file.isEmpty()) {
            return "上传失败,请选择文件";
        }
        String fileName = file.getOriginalFilename();
        String filePath = "要存文件的地址";
        File dest = new File(filePath + fileName);
        try {
            System.out.println("ok");
            file.transferTo(dest);
            // LOGGER.info("上传成功");
            return "上传成功";
        } catch (IOException e) {
            // LOGGER.error(e.toString(), e);
        }
        return "上传失败!";
    }
}
上一篇:Python爬取笔趣阁小说


下一篇:node.js核心模块 path模块