简体   繁体   English

如何使用多部分/表单数据?

[英]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.

相关问题 如何在同一个jsp页面中查看jsp表单请求提交? (ENCTYPE =“多部分/格式数据”) - How can i check jsp form request submit in same jsp page? (enctype=“multipart/form-data”) Spring 我可以使用 multipart/form-data 发布参数数组吗 - Spring Can I post params array with multipart/form-data 如何使用AngularJS $ http发送multipart / form-data - How to use AngularJS $http to send multipart/form-data 如何在Spring MVC中使用multipart / form-data - how to use multipart/form-data in spring mvc 如何在 Spring Cloud Gateway 中编辑 multipart/form-data 请求数据? - How can I edit multipart/form-data request data in Spring Cloud Gateway? 如何处理需要在 Spring 引导中发送 JSON 和 multipart/form-data 的情况 - How can I handle a situation where I need to send JSON and multipart/form-data in Spring boot 如何在java servlet中处理multipart / form-data POST请求? - How can I handle multipart/form-data POST requests in my java servlet? 如何将GZIP内容编码应用于HTTP文件上传multipart / form-data POST - How can I apply GZIP content-encoding to an HTTP file upload multipart/form-data POST 如何使用 Java 发出多部分/表单数据 POST 请求? - How can I make a multipart/form-data POST request using Java? 如何在 Spring MVC 控制器中接收多部分/表单数据? - How can I receive multipart/form-data in Spring MVC Controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM