For downloading a file I will add the "Content-Disposition" to my responseHeader but it doesn't work.
The response will not have any added properties.
@Bean
public ExpressionParser fileParser() {
return new SpelExpressionParser();
}
@Bean
public HeaderMapper<HttpHeaders> fileHeaderMapper() {
return new DefaultHttpHeaderMapper();
}
@Bean
public IntegrationFlow httpGetFileDownload() {
return IntegrationFlows.from(
Http.inboundGateway("/api/files/download/{id}")
.requestMapping(r -> r.methods(HttpMethod.GET))
.statusCodeExpression(fileParser().parseExpression("T(org.springframework.http.HttpStatus).BAD_REQUEST"))
.payloadExpression(fileParser().parseExpression("#pathVariables.id"))
.crossOrigin(cors -> cors.origin("*").exposedHeaders("Content-Disposition", "content-disposition"))
.headerMapper(fileHeaderMapper())
)
.channel("http.file.download.channel")
.handle("fileEndpoint", "download")
.get();
}
public Message<?> download(Message<Long> msg){
...
return MessageBuilder
.withPayload(resource)
.copyHeaders(msg.getHeaders())
.setHeader(STATUSCODE_HEADER, HttpStatus.OK)
.setHeader(HttpHeaders.CONTENT_DISPOSITION,"attachment;filename=" + file.getName())
.setHeader(HttpHeaders.CONTENT_TYPE, mimeType)
.setHeader(HttpHeaders.CONTENT_LENGTH, (int)file.length())
.build();
}
What I get:
cache-control: "no-cache, no-store, max-age=0, must-revalidate"
content-type: "application/json"
expires: "0"
pragma: "no-cache"