问题
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:
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
The Rest Controller looks so:
@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]
If I use "MultipartFile" instead of any, then is file 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?
回答1:
Retrofit has documentation on FORM ENCODED AND MULTIPART
The gist is to annotate the function with @Multipart
and annotate your file as @Part
来源:https://stackoverflow.com/questions/57789109/how-can-i-use-multipart-form-data