From the wording of your question it sounds like you want the server framework to set the following header for you so that the data flows back in chunked blocks:

Transfer-Encoding: chunked

To do that you need to supply a Spring resource where the full size is not known in advance. You have used ByteArrayResource where the full size is known and results in a Content-Length header being set in the response and chunked is not used.

Change your code to use InputStreamResource and the service will stream the response back to the client with a chunked transfer encoding and no content length. Here's a sample (syntax unchecked):

try(ByteArrayInputStream bis = new ByteArrayInputStream(fileDetailDto.getData())) {
  return ResponseEntity.ok().contentType(new MediaType("text", "csv"))
          .header(HttpHeaders.CONTENT_DISPOSITION,
              "attachment; filename=\"" + fileDetailDto.getFileName() + "\"")
          .body(new InputStreamResource(bis));
}

While this will get you a chunked response I'm not convinced it's the root of your problems with the browser because they are all very capable of asynchronously streaming back data regardless of how the server provides it.

Answer from Andy Brown on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 47505245 › how-to-download-large-data-file-by-java-code-where-data-is-fetching-in-chunks
How to download large data file by java code where data is fetching in chunks? - Stack Overflow
Sign up to request clarification or add additional context in comments. ... I don't want to read stream data.. Plz read my question again as I updated this. Tq 2017-11-27T07:54:28.813Z+00:00 ... URL url = new URL("http://large.file.dat"); Path path = Paths.get("/home/it/documents/large.file.dat"); Files.copy(url.openStream(), path); Chunked should not matter, unless you want to work with parts of a file, when the connection is likely to fail after a time.
🌐
Coderanch
coderanch.com › t › 209906 › java › Download-files-chunk-sizes
Download files in chunk sizes (Distributed Java forum at Coderanch)
This "chunking" behavior already occurs at a lower level - it's part of the TCP/IP network "stack" to break large files (or any sort of transmission) into manageable smaller packages. You could still implement this at a higher level, but I'm not sure what you would gain from it, unless just as an exercise. What sort of technology were you planning on using? Unfortunately, "Rahul" does not meet the JavaRanch Naming Policy.
🌐
Enterprisedt
enterprisedt.com › questions › index.php › 11776 › is-it-possible-to-download-large-files-in-chunks
Is it possible to download large files in chunks? - EnterpriseDT Q&A
May 19, 2017 - I have tried DownloadByteArray() and DownloadStream() for downloading binary files of ~450 MByte. ... use does not necessarily solve my problem.
🌐
Javaprogrammingforums
javaprogrammingforums.com › java-theory-questions › 29907-downloading-files-efficiently.html
[SOLVED] Downloading files efficiently
June 8, 2013 - 4. I chose fixed 8kbyte read chunks. Reason is there's no reason to update the GUI 100 times in a few milliseconds for reading really small images, and 8kbytes effectively loads a typical disk drive (this is the default buffered streams use). You can try experimenting with larger read chunks, too.
🌐
Google Cloud
cloud.google.com › cloud storage › download a file in chunks concurrently
Download a file in chunks concurrently | Cloud Storage | Google Cloud Documentation
Threads can be used instead # of processes by passing `worker_type=transfer_manager.THREAD`. # workers=8 from google.cloud.storage import Client, transfer_manager storage_client = Client() bucket = storage_client.bucket(bucket_name) blob = bucket.blob(blob_name) transfer_manager.download_chunks_concurrently( blob, filename, chunk_size=chunk_size, max_workers=workers ) print("Downloaded {} to {}.".format(blob_name, filename)) To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser. Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
🌐
amitph
amitph.com › home › java › java large files – efficient processing
Java Large Files - Efficient Processing - amitph
November 22, 2024 - This detailed practical comparison concludes that using a buffer is the best way to transfer a large amount of data using Java IO. Copying the file in chunks helps to limit the amount of consumed memory consumed by the file content.
Find elsewhere
🌐
GitHub
github.com › box › box-java-sdk › issues › 916
Download a large file in batches · Issue #916 · box/box-java-sdk
September 13, 2021 - Description of the Issue I want to download all the files from Box and upload to AWS S3 bucket. I am looking into APIs for that and found i can do using below, BoxFile file = new BoxFile(api, "id"); BoxFile.Info info = file.getInfo(); Fi...
Author   box
🌐
Stack Overflow
stackoverflow.com › questions › 70952820 › how-to-transfer-file-chunks-for-large-file-download-and-reconstruct-it-in-javasc
java - How to transfer file chunks for large file download and reconstruct it in javascript? - Stack Overflow
February 2, 2022 - you can track the fetch by measuring the progress for that store the total file size · const contentLength = +response.headers.get('Content-Length'); in ordre to track the recieved bytes let receivedLength = 0; ... while(true) { const {done, value} = await reader.read(); if (done) { break; } chunks.push(value); receivedLength += value.length; let compleated = Math.round(receivedLength/contentLength*100); console.log(`Received ${receivedLength} of ${contentLength}`) } after the while loop has broken you can check if the transfer is fully completed or not
🌐
Google
developers.google.com › api client libraries › java › resumable media downloads
Resumable Media Downloads | API Client Library for Java | Google for Developers
April 23, 2026 - Resumable media download is enabled ... files. When you download a large media file from a server, use resumable media download to download the file chunk by chunk....
🌐
Medium
medium.com › @souravdas08 › download-large-files-over-rest-http-api-aa6a00a050cf
Download large files over REST/HTTP API | by Sourav Das | Medium
April 2, 2024 - JAVA: Constant usage of 800 - 900 MB memory until all files got downloaded. * clearly evident, as both the servers reduced their memory utilization by breaking the entire data into smaller part and reusing the same space for different parts of the file. Utilizing pipes and streams offers several advantages: ... Using pipes and streams breaks down data into small chunks, making it easier to handle.
🌐
Coderanch
coderanch.com › t › 205763 › java › download-file-chunks
how can i download a file in chunks. (Sockets and Internet Protocols forum at Coderanch)
October 13, 2016 - So you are most likely going to have to use the FTP protocol and hope that the FTP server supports the RESTART (REST) command. You can find the white paper here RFC 959 on the full FTP protocol. This is the pertinent statement on the REST command: RESTART (REST) The argument field represents the server marker at which file transfer is to be restarted.
🌐
amitph
amitph.com › home › spring › downloading large files using spring webclient
Downloading Large Files using Spring WebClient - amitph
November 22, 2024 - Example of Using WebClient to download large file in chunks and write to the disk · Flux<DataBuffer> dataBuffer = webClient .get() .uri("/largefiles/1") .retrieve() .bodyToFlux(DataBuffer.class); DataBufferUtils.write(dataBuffer, destination, StandardOpenOption.CREATE) .share().block();Code language: Java (java)
🌐
Google Groups
groups.google.com › g › microprofile › c › dP-KGmwVRkI
How to download large files (>1GB) with Java
you shouldn't return tye byte[] but the Stream straight, in this way the 1GB file won't be loaded into memory. Maybe StreamingOutput api can help.
🌐
Baeldung
baeldung.com › home › java › java io › download a file from an url in java
Download a File From an URL in Java | Baeldung
January 8, 2024 - Another common way to use the Range header is for downloading a file in chunks by setting different byte ranges.
🌐
GitHub
gist.github.com › jpt1122 › 63cd35b691b049567b00
Sometimes we need to fragment large files into smaller chunks. For example, in simple application which is used with server, we need to upload files ( video, image etc. ) But if the size of file is major,uploading large files to server could get some time and we may face with some problems. In order to avoid these problems, we have to follow these steps; first, we need to determine maximum size of each chunk.( 1Mb, 500Kb..) Second, we must partition whole file. At this point we could use byte array, like bu
Download ZIP · Sometimes we need to fragment large files into smaller chunks. For example, in simple application which is used with server, we need to upload files ( video, image etc. ) But if the size of file is major,uploading large files to server could get some time and we may face with some problems. In order to avoid these problems, we have to follow the… · Raw · ByteReadAndWrite.java ·
🌐
DZone
dzone.com › coding › frameworks › writing a download server part i: always stream, never keep fully in memory
Writing a Download Server Part I: Always Stream, Never Keep Fully in Memory
June 24, 2015 - The easiest one is to copy bytes manually: @RequestMapping(method = GET) public void download(OutputStream output) throws IOException { try(final InputStream myFile = openFile()) { IOUtils.copy(myFile, output); } }