首先在后端新建一个controller:
![请添加图片描述](https://img-blog.csdnimg.cn/753ece428e1d4ad39113fed0db87ca0c.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5aSc6Imy5p625p6E5biI,size_20,color_FFFFFF,t_70,g_se,x_16)
代码:
package com.example.demo.controller;
import cn.hutool.core.io.FileUtil;
import com.example.demo.common.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@RestController
@RequestMapping("/files")
public class FileController {
@PostMapping("/upload")
public Result<?> upload(MultipartFile file) throws IOException { // MultipartFile:用来接受前端传过来的对象
String originalFilename = file