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(
@RequestParam("deployment-name")
deploymentName: String,
@RequestParam("enable-duplicate-filtering")
enableDuplicateFiltering: String?,
@RequestParam("deploy-changed-only")
deployChangedOnly: String,
@RequestParam("deployment-source")
deploymentSource: String,
@RequestParam("tenant-id")
tenantId: String,
@RequestParam("data")
data: MultipartFile
) {
println(deploymentName)
println(deployChangedOnly)
println(deploymentSource)
println(tenantId)
println(data.toString())
}
For all params that works, but for the last one that doesn’t work.
I’ve tried to give a name “data”, “*”, “file” that doesn’t work.
Required request part ‘data’ is not present
The Controller doesn’t see that file.
I’ve tried too to use Retrofit:
@PostMapping("/data/deployment/create")
@Multipart
fun uploadDmn(
@Part("data")
data: MultipartFile
) {
println(data.toString())
}
But that doesn’t work too:
Parameter specified as non-null is null
How can I work with that content type? multipart/form-data
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?