【发布时间】:2018-08-16 05:45:29
【问题描述】:
我正在尝试将文件从客户端上传到服务器,客户端使用 curl 命令将文件上传到服务器
客户端命令:
curl -X POST -T pom.xml http://localhost:8070/put --header "origmd5":"7AB4E6F0A4A2D3CBB200DB1677D99AD75"
现在在控制器中,即在服务器端,代码如下
服务器端:
@PostMapping(value="readFile")
public ResponseEntity<?> uploadfile(@RequestBody String filecontent) throws IllegalStateException, IOException {
System.out.println(filecontent);//prints the content which is inside the file uploaded by client
return null;
}
1.现在的问题说明是如何获取客户端已经发送的文件名,文件的内容可以在请求体中解析,但是如何获取文件名呢?
@RequestBody String filecontent
2.我使用上面的字符串来解析请求正文(即文件内容存储在字符串中)这是将文件内容存储在字符串中的正确方法吗?
【问题讨论】:
-
如果文件是请求的正文,则不能。您必须在请求中添加一个附加参数。
标签: java spring web-services spring-mvc spring-boot