以下将演示:如何使用AntD的上传组件,结合axios工具,向Spring MVC服务端上传文件。
前端发送
基于AntD的上传组件,采用手工上传模式;上传的同时,附加了一个
category
参数;
const [category, setCategory] = useState<any>();const [fileList, setFileList] = useState<UploadFile[]>([]);const handleUpload = () => {// 参数let params = {category, file: fileList[0] as FileType}// 发送axios.post('/submit', params).then((data: any) => {postForm([]);notify.success({message: '上传成功', description: data, duration: 300});});
};
服务端接收
@ResponseBody
@RequestMapping(value = "/submit", method = RequestMethod.POST)
public Result<String> create(@RequestParam String category, @RequestParam MultipartFile file) {// file.getInputStream()// TODO:
}