Content-Disposition 文件名可以用于带有 Spring Web 客户端的多部分表单中的文本字段吗?
Can Content-Disposition filename be used for text fields in multipart forms with Spring Webclient?
使用 Service-Now API(例如)需要请求提供以下内容:
POST /api/now/attachment/upload HTTP/1.1
Host: somehost.testenv.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MadHyZrFTrZu0gW
cache-control: no-cache
Content-Disposition: form-data; name="table_name"
some_table
Content-Disposition: form-data; name="table_sys_id"
82c9aca7kljasdfkljhasdfec8dfdb61d961920
Content-Disposition: form-data; name="uploadFile"; filename="undefined"
Content-Type: file
------WebKitFormBoundary7MA4YWxkTrZu0gW—
以上是使用 Postman 并提供 form-data
个键值对生成的。
但是,基于定义 Content-Disposition 的 RFC 的摘要:https://www.rfc-editor.org/rfc/rfc2183。
Two values for this
header field are described in this memo; one for the ordinary linear
presentation of the body part, and another to facilitate the use of
mail to transfer files.
Spring Webflux (https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/ContentDisposition.html) 中使用的 Content-Disposition class 仅包含一个字符串形式的“文件名”内部字段。
org.springframework.http 中的 ContentDisposition class 是否缺少符合 RFC-2183 标准值的组件(body 部分的普通线性表示)?
spring代码自动生成的HTTP请求如下:
POST /api/now/attachment/upload HTTP/1.1
user-agent: ReactorNetty/0.7.9.RELEASE
transfer-encoding: chunked
host: somehost.testenv.com
accept: */*
accept-encoding: gzip
Content-Type: multipart/form-data;boundary=o-0JsSvUdGo98NDHJSWTwjvgzlRSXsmJ98-pWQ;charset=UTF-8
这是生成上述 HTTP 请求的源代码:
MultipartBodyBuilder mbuilder = new MultipartBodyBuilder();
mbuilder.part("table_name", snConfig.getChangeRecordTableName());
mbuilder.part("table_sys_id", result.get(0).getSysId());
mbuilder.part("uploadFile", someFile);
return client.post()
.uri(snConfig.getEndpointAttachmentUpload())
.contentType(MediaType.MULTIPART_FORM_DATA)
.syncBody(mbuilder.build())
.retrieve()
.bodyToMono(AttachmentUploadResult.class);
看起来代码将所有 MultipartBodyBuilder 组件存储到一个 multipart/form-data 中,这与工作 HTTP 请求的格式不同。
然而,即使通过手动提供 Content-Disposition headers,也只能创建一个值为“文件名”的 name/value 对。
Content-Disposition 缺少功能吗? WebClient 可以吗?
在研究了很长时间后,WebClient 似乎不支持此功能。
使用 Service-Now API(例如)需要请求提供以下内容:
POST /api/now/attachment/upload HTTP/1.1
Host: somehost.testenv.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MadHyZrFTrZu0gW
cache-control: no-cache
Content-Disposition: form-data; name="table_name"
some_table
Content-Disposition: form-data; name="table_sys_id"
82c9aca7kljasdfkljhasdfec8dfdb61d961920
Content-Disposition: form-data; name="uploadFile"; filename="undefined"
Content-Type: file
------WebKitFormBoundary7MA4YWxkTrZu0gW—
以上是使用 Postman 并提供 form-data
个键值对生成的。
但是,基于定义 Content-Disposition 的 RFC 的摘要:https://www.rfc-editor.org/rfc/rfc2183。
Two values for this
header field are described in this memo; one for the ordinary linear
presentation of the body part, and another to facilitate the use of
mail to transfer files.
Spring Webflux (https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/ContentDisposition.html) 中使用的 Content-Disposition class 仅包含一个字符串形式的“文件名”内部字段。
org.springframework.http 中的 ContentDisposition class 是否缺少符合 RFC-2183 标准值的组件(body 部分的普通线性表示)?
spring代码自动生成的HTTP请求如下:
POST /api/now/attachment/upload HTTP/1.1
user-agent: ReactorNetty/0.7.9.RELEASE
transfer-encoding: chunked
host: somehost.testenv.com
accept: */*
accept-encoding: gzip
Content-Type: multipart/form-data;boundary=o-0JsSvUdGo98NDHJSWTwjvgzlRSXsmJ98-pWQ;charset=UTF-8
这是生成上述 HTTP 请求的源代码:
MultipartBodyBuilder mbuilder = new MultipartBodyBuilder();
mbuilder.part("table_name", snConfig.getChangeRecordTableName());
mbuilder.part("table_sys_id", result.get(0).getSysId());
mbuilder.part("uploadFile", someFile);
return client.post()
.uri(snConfig.getEndpointAttachmentUpload())
.contentType(MediaType.MULTIPART_FORM_DATA)
.syncBody(mbuilder.build())
.retrieve()
.bodyToMono(AttachmentUploadResult.class);
看起来代码将所有 MultipartBodyBuilder 组件存储到一个 multipart/form-data 中,这与工作 HTTP 请求的格式不同。
然而,即使通过手动提供 Content-Disposition headers,也只能创建一个值为“文件名”的 name/value 对。
Content-Disposition 缺少功能吗? WebClient 可以吗?
在研究了很长时间后,WebClient 似乎不支持此功能。