Skip to content

Support Custom Headers for Multipart Async Data [SPR-16376] #20922

Closed
@spring-projects-issues

Description

@spring-projects-issues

Marc-Christian Schulze opened SPR-16376 and commented

In order to upload a file using the newly introduced method (cf. #20854)

public static <T, P extends Publisher<T>> 
MultipartInserter BodyInserters::fromMultipartAsyncData (
  String key, 
  P publisher, 
  Class<T> elementClass
)

it's necessary to specify the filename and content type along with the publisher.

Right now when streaming asynchronously file content into a multipart request

Publisher<ByteBuffer> filePublisher = ...
WebClient 
  .create(baseUrl) 
  .post() 
  .uri("...") 
  .body(BodyInserters.fromMultipartAsyncData("file", filePublisher, ByteBuffer.class)) 

the resulting http request looks like:

--ZAbh_nuM150m0P4R_zq9ywXiM_pJ0IKJq 
Content-Disposition: form-data; name="file" 
 
 ...... 
--ZAbh_nuM150m0P4R_zq9ywXiM_pJ0IKJq-- 

As you can see the file name and the content type is not specified. For a correct file upload I would expect the http request to look like:

--ZAbh_nuM150m0P4R_zq9ywXiM_pJ0IKJq 
Content-Disposition: form-data; name="file"; filename="myFile.txt"
Content-Type: application/octet-stream 
 
 ...... 
--ZAbh_nuM150m0P4R_zq9ywXiM_pJ0IKJq-- 


Affects: 5.0.2

Issue Links:

Referenced from: commits 646fcc5, 283811b

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions