How can I use multipart/form-data?

﹥>﹥吖頭↗ 提交于 2021-01-07 03:22:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!