spring boot 中header 中如何设置文件大小来显示下载进度?

How to set file size in the header in spring boot to display the download progress?

如何在header中设置file size在spring开机时在客户端显示下载进度?

@GetMapping(value = "/document/{nodeRef}/{versionNumber}")
public byte[] getDocumentWithVersion(@PathVariable(value = "nodeRef") UUID nodeRef, @PathVariable(value = "versionNumber") Double versionNumber) {
    return docService.getDocument(nodeRef, versionNumber);
}

客户端在filebody开始下载之前收到header。所以在 header.

中添加了 Content-lengthcontent-type
@GetMapping(value = "/document/{nodeRef}/{versionNumber}")
public ResponseEntity<byte[]> getDocumentWithVersion(@PathVariable(value = "nodeRef") UUID nodeRef, @PathVariable(value = "versionNumber") Double versionNumber) {
    byte[] file = alfrescoService.getDocument(null, nodeRef, versionNumber);
    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(file.length));
    headers.add(HttpHeaders.CONTENT_TYPE, "application/octet-stream");
    return ResponseEntity.ok().headers(headers).body(file);
}