本地文件上传至服务器

@PostMapping(value = "/uploadProFile")
@ResponseBody
public String uploadProFile(@RequestBody MultipartFile file) throws IOException {
    File fileex = new File(this.uploadFileDir);// 文件路径
    if (!fileex.exists()) fileex.mkdirs();
    String fileUrl=this.uploadFileDir+"\\"+UUID.randomUUID()+file.getOriginalFilename();
    try{
        file.transferTo(new File(fileUrl));
    }catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return fileUrl;
}

猜你喜欢

转载自blog.csdn.net/TQGoGo/article/details/108039446