主要用于分割key-value对,多个kv之间使用boundary来进行分割
参考自:
【java|multipart/form-data中boundary的作用】https://stackoverflow.com/questions/3508338/what-is-the-boundary-in-multipart-form-data#:~:text=multipart%2Fform%2Ddata%20contains%20boundary,type%20of%20a%20request%20header.
multipart/form-data contains boundary to separate name/value pairs. The boundary acts like a marker of each chunk of name/value pairs passed when a form gets submitted. The boundary is automatically added to a content-type of a request header.
The form with enctype="multipart/form-data" attribute will have a request header Content-Type : multipart/form-data;
boundary --- WebKit193844043-h (browser generated vaue).
The payload passed looks something like this:
Content-Type: multipart/form-data;
boundary=---WebKitFormBoundary7MA4YWxkTrZu0gW-----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data;
name=”file”;
filename=”captcha”
Content-Type:-----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data;
name=”action”submit
-----WebKitFormBoundary7MA4YWxkTrZu0gW--
On the webservice side, it's consumed in @Consumes("multipart/form-data") form.
Beware, when testing your webservice using chrome postman, you need to check the form data option(radio button) and File menu from the dropdown box to send attachment. Explicit provision of content-type as multipart/form-data throws an error. Because boundary is missing as it overrides the curl request of post man to server with content-type by appending the boundary which works fine.
推荐阅读
- java|java8 stream collect方法
- java|springcloud-alibaba springSecurity整合oauth2 授权码模式
- flowable工作流技术学习
- JAVA|Spring boot 提示“Whitelabel Error Page”
- Spring|Spring Boot整合dubbo+Nacos实战(二)
- 个人领悟|SpringBoot学习笔记
- 个人领悟|在电脑上使用tomcat部署项目时的常见问题
- JavaWeb学习记录——servlet+tomcat+request+respond+JSP实战项目(使用MVC模式开发)
- 编程语言|宁愿“大小周”、每天只写 200 行代码、月薪 8k-17k 人群再涨!揭晓中国开发者真实现状...