java - 在 python3 中上传文件异常使用“请求”模块
问题描述
我尝试运行以下 python 代码,但服务器 错误消息出现错误:org.springframework.web.multipart.support.MissingServletRequestPartException:所需的请求部分“文件”不存在\n\tat org.springframework.web。 method.annotation.RequestParamMethodArgumentResolver.handleMissingValuexxx
下面的python代码
header = {'Content-Type': 'multipart/form-data;'}
with open(filepath, 'rb') as ff:
files = { 'file': ff }
r = requests.post( url=url, headers=header, files=files)
print(r.text)
下面是java的服务器代码
public MessageVO uploadFile(@RequestParam("file") MultipartFile file) {
try {
BackResultVO<UploadfileVo> mes = fileService.uploadCommonFile(file);
MessageVO<UploadfileVo> uploadfileVoMessageVO = MessageVO.back(mes.getCode(),mes.getMsg());
MessageVO<String> loadfile = this.loadfile(mes.getData().getFilePath());
mes.getData().setFileDownUrl(loadfile.getData());
uploadfileVoMessageVO.setError(mes.getError());
uploadfileVoMessageVO.setData(mes.getData());
return uploadfileVoMessageVO;
} catch (Exception e) {
e.printStackTrace();
return MessageVO.back(MessageVO.Code.EXCEPTION, "failed"+e.getMessage());
}
}
请帮忙
解决方案
推荐阅读
- javafx - JavaFX8如何在使用TAB或其他键遍历时请求关注表格视图中的图形节点?
- hibernate - 在休眠中设置相互引用应该发生在工作单元内还是可以在工作单元外完成?
- c++ - 如何覆盖 QApplication::exec()
- javascript - 如何编写一个 JavaScript 函数,该函数接受一个包含姓名和分数的数组,并返回包含字母成绩和学生的数组?
- asp.net - ASP.Net 和公理
- node.js - 请求执行的快速路由器顺序:`/state/:params` vs `/state/absolute-path`
- python - 在 csv 文件中转换为浮点数的字符串
- php - 错误如果条件在 2 月 29 日在 php 中不起作用,当我设置日期 2 月 29 日时它显示第一个条件 true1
- c# - Asp .Net Grid 与行中的多个控件然后如何在单击单个按钮时同时执行插入、更新和删除操作
- machine-learning - CNN 填充和跨步