spring-boot - Webflux Webclient 未设置 Content-Range 标头
问题描述
使用flux Webclient,我正在尝试org.springframework.core.io.buffer.DataBuffer
将从另一个Webclient 下载的文件流式传输到新端点。
此端点(我无法控制)需要在上传时设置 2 个标头:Content-Length
和Content-Range
.
如果我按照下面的硬编码测试手动设置它们,一切顺利。随着 Flux 数据缓冲区的上传,我不确定从哪里开始动态设置这些设置。
public Mono<ResourceResponse>uploadFile(URI destination, Flux<DataBuffer> inputFile){
WebClient webClient = WebClient.create();
return webClient.put()
.uri(destination)
// .header(HttpHeaders.CONTENT_LENGTH, "12")
// .header(HttpHeaders.CONTENT_RANGE, "bytes 0-11/12")
.body(BodyInserters.fromDataBuffers(inputFile))
.retrieve()
.bodyToMono(ResourceResponse.class);
}
我应该在客户端上做更多的事情来提取这些标头吗?
public Flux<DataBuffer> downloadFile(URI uri) {
return botClient.get().uri(uri)
.accept(MediaType.APPLICATION_OCTET_STREAM)
.retrieve().bodyToFlux(DataBuffer.class);
}
解决方案
推荐阅读
- google-cloud-ml - Google Cloud AI 平台上的 TensorFlow 2
- c# - Dapper sql select查询与join语句,多重映射错误
- java - 如何将 FOP 1.0 升级到 FOP 2.4 - 缺少 org.apache.fop.apps.Driver、org.apache.fop.messaging.MessageHandler
- javascript - 使用 jquery 留下另一个输入时移动到特定的选项卡索引
- python - how do I remove commas within columns from data retrieved from a CSV file
- qt - 将 Qt 函数导入 QML 文件?
- javascript - 无法使用 javascript 访问脚本标记中存在的变量的值
- python - 如何修复将 django 1.10 升级到 1.11 时出现的错误?
- sas - 我需要在 Proc sql 中找到前 5 个 Transaction_Due_Date
- c# - 如何将两个复选框绑定到一个按钮