[英]How can I use multipart/form-data?
I need to implement a REST-Endpoint, that receives multipart/form-data我需要实现一个 REST-Endpoint,它接收 multipart/form-data
I use我用
- Spring Boot - 弹簧靴
- Kotlin - 科特林
- Spring MVC - 春季MVC
A multipart form submit with the following parts:多部分表单提交包含以下部分:
deployment-name ----- text/plain部署名称 ----- 文本/纯文本
enable-duplicate-filtering ----- text/plain启用重复过滤 ----- 文本/纯文本
deploy-changed-only ----- text/plain仅部署更改 ----- 文本/纯文本
deployment-source ----- text/plain部署源 ----- 文本/纯文本
tenant-id ----- text/plain租户 ID ----- 文本/纯文本
* ----- application/octet-stream * ----- 应用程序/八位字节流
The Rest Controller looks so: Rest Controller 看起来是这样的:
@PostMapping("/data/deployment/create")
fun uploadDmn(@RequestBody() file: Any){
}
When I receive a request, then there is an error:当我收到请求时,出现错误:
Content type 'multipart/form-data;boundary=--------------------------914124725006223485188585;charset=UTF-8' not supported]内容类型 'multipart/form-data;boundary=------------------------914124725006223485188585;charset=UTF-8' 不支持]
If I use "MultipartFile" instead of any, then is file NULL.如果我使用“MultipartFile”而不是 any,则文件为 NULL。
@PostMapping("/data/deployment/create")
fun uploadDmn(@RequestBody() file: MultipartFile){
}
Example of Request:请求示例:
--28319d96a8c54b529aa9159ad75edef9
Content-Disposition: form-data; name="deployment-name"
aName
--28319d96a8c54b529aa9159ad75edef9
Content-Disposition: form-data; name="enable-duplicate-filtering"
true
--28319d96a8c54b529aa9159ad75edef9
Content-Disposition: form-data; name="deployment-source"
process application
--28319d96a8c54b529aa9159ad75edef9
Content-Disposition: form-data; name="data"; filename="test.bpmn"
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions ...>
<!-- BPMN 2.0 XML omitted -->
</bpmn2:definitions>
--28319d96a8c54b529aa9159ad75edef9--
Can anyone help please?有人可以帮忙吗?
Retrofit has documentation on FORM ENCODED AND MULTIPART
Retrofit 有关于FORM ENCODED AND MULTIPART
文档
The gist is to annotate the function with @Multipart
and annotate your file as @Part
要点是用@Multipart
注释函数并将您的文件注释为@Part
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.