如何使用multipart/form-data? [英] How can I use multipart/form-data?
问题描述
我需要实现一个REST端点,该端点可以接收multipart/form-data
我使用
-春季靴
-Kotlin
-Spring MVC
I need to implement a REST-Endpoint, that receives multipart/form-data
I use
- Spring Boot
- Kotlin
- Spring MVC
多部分表单提交,包括以下部分:
A multipart form submit with the following parts:
部署名称-----文本/纯文本
启用重复过滤-----文本/纯文本
仅部署更改的-----文本/纯文本
部署源-----文本/纯文本
租户ID -----文本/纯文本
* ----- application/octet-stream
deployment-name ----- text/plain
enable-duplicate-filtering ----- text/plain
deploy-changed-only ----- text/plain
deployment-source ----- text/plain
tenant-id ----- text/plain
* ----- application/octet-stream
Rest Controller的外观如下:
The Rest Controller looks so:
@PostMapping("/data/deployment/create")
fun uploadDmn(@RequestBody() file: Any){
}
当我收到请求时,出现错误:
When I receive a request, then there is an error:
内容类型'multipart/form-data; boundary = -------------------------- 914124725006223485188585; charset = UTF-8'不支持]
Content type 'multipart/form-data;boundary=--------------------------914124725006223485188585;charset=UTF-8' not supported]
如果我使用"MultipartFile"而不是任何文件,则文件为NULL.
If I use "MultipartFile" instead of any, then is file NULL.
@PostMapping("/data/deployment/create")
fun uploadDmn(@RequestBody() file: MultipartFile){
}
请求示例:
--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--
任何人都可以帮忙吗?
推荐答案
Retrofit在 FORM ENCODED AND MULTIPART
Retrofit has documentation on FORM ENCODED AND MULTIPART
要点是用@Multipart
注释功能并将文件注释为@Part
The gist is to annotate the function with @Multipart
and annotate your file as @Part
这篇关于如何使用multipart/form-data?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!