Empower growth and innovation with the latest Program Dev insights

Small Excel Exports Open but a Large One with Tens of Thousands of Rows Says the File Is Corrupted: Is the Large File Being Truncated Mid-Transfer?

Nov 19, 2026 Read: 21

A small Excel export from the backend opens, but a large export with tens of thousands of rows reports 'file is corrupted.' In most cases the compression algorithm itself is not broken; the large file has been truncated somewhere in the delivery chain. Based on common project delivery experience in 2026, first check whether the actual downloaded byte count matches Content-Length, then check whether Content-Encoding has been added again by an intermediate layer, and only then revisit the compression switch. The reason small files never reveal the problem is that they are still far from the gateway's buffering limit and timeout threshold.

Small Exports Open but Large Ones Fail: The Difference Is Usually Not the Compression Algorithm

gzip only sees bytes, not content. For a format such as xlsx, which is already a compressed container, compressing it again usually yields only a few percentage points of benefit, and the difference in compression ratio between a few MB and tens of MB is not fundamental. Therefore, the pattern of 'small files work, large files are corrupted' usually points not to compression ratio but to file size crossing a processing threshold at some layer: the gateway's response buffer limit, the proxy's connection idle timeout, or the application assembling the entire file in memory before sending it. When any of these limits is reached, the response ends early.

Another common mismatch is in the response headers. Content-Length may contain the pre-compression length, or it may not have been updated after compression, so the browser and proxy truncate according to the wrong length. If an intermediate chunked encoding layer ends early, the download may appear to finish completely while bytes are missing at the end of the file. When Excel cannot open the file, its message is often only a generic 'file is corrupted'; it cannot tell whether a few KB are missing or whether the content has been replaced by an error page.

  • Already-compressed containers: xlsx, docx, pdf, zip, and images; compressing them again has low benefit and a higher chance of error.
  • Text-based responses: JSON, HTML, and CSV; compression provides clear benefit and is where compression should be allowed to work.
  • Streaming exports: for exports that query and write at the same time, the compression stream and output stream must have exactly the same lifecycle; closing one early leaves a partial file.

There Are at Least Three Places in the Chain That Can Truncate the File

When troubleshooting, it is easy to suspect the code first, but along the export chain there are more places than expected that can cause an 'incomplete file.' Based on common delivery chains in 2026, counting from the backend forward, there are roughly three places, and each one behaves a little differently.

  1. Application layer: compression middleware also applies gzip to binary responses such as application/octet-stream, or the export logic writes an error message after the compression stream has closed, so the output becomes half a file plus a piece of text.
  2. Gateway or reverse proxy: the response buffer has a limit; once exceeded, it either forwards in chunks or truncates directly. When the connection idle timeout is too short, a download of tens of MB is cut off mid-transfer, and the client only sees the connection end without an error.
  3. CDN or cache layer: one bad response gets cached, and after that every refresh is bad, which is easily misdiagnosed as incorrect code; changing the code and redeploying at this point leaves the symptom unchanged.

These three places also share a common trait: when connecting directly to the backend locally, they are usually bypassed, so 'works locally, fails online' is almost the default signal for this kind of problem.

Troubleshooting Order: Measure Bytes First, Then Touch the Compression Switch

A time-saving approach is to align three things from back to front: what the response headers say, how many actual bytes there are, and what type the front end receives. The value of this order is that each step can be independently falsified, avoiding changing several places at once and ending up unable to tell what fixed it.

  1. Check the response headers: confirm that the type is the MIME type for xlsx, and check whether Content-Encoding has unexpectedly had gzip added.
  2. Compare lengths: use the command line or the browser network panel to see whether the actual downloaded byte count matches Content-Length; a consistent shortfall basically means truncation.
  3. Verify with another client: call the same endpoint directly from the address bar or command line; if it opens normally, the problem lies in how the front end reads the response.
  4. Check what the front end receives: whether the request declares a blob response type, and whether the returned content is concatenated as a string or decoded again.

After these four steps, most cases can already be narrowed down to a specific layer. Only after that should you look at whether the compression configuration itself needs adjustment; by then any change is based on evidence.

Delivery Site: Constraints When the Buffer Limit Becomes the Bottleneck

In a common type of backend project, the client requires all endpoints to go through the same gateway, and before the export feature went live it was load-tested only with small files in the test environment. When real data volume arrived, the exported xlsx grew from a few MB to tens of MB, and operations only reported in a batch at month-end reconciliation that the files would not open.

The site constraint was that changing gateway buffer and timeout parameters requires a change process, which by experience range usually takes one to three business days; meanwhile this batch of exports was a hard requirement for month-end reconciliation and could not wait. The approach taken at the time was to first explicitly disable compression for binary downloads on the application side, change the response to generate and output at the same time, and cap the number of rows per export to a controllable range to stop the bleeding; gateway parameters would then be standardized on a schedule. The cost was maintaining an additional type whitelist for export endpoints, so every new export format required another review, and the row cap forced operations to split exports into multiple runs, adding manual work. The result was that large files could be downloaded reliably, but reconciliation definitions and operating habits both had to be adjusted once.

There is also an experience range to reference for this kind of site: when a single export file is within a few hundred KB, most chain problems do not surface; once it reaches the typical range of a few MB to tens of MB, the boundaries of buffering, timeout, and memory begin to matter. If load testing covers only small files, the risk is effectively left for real data to reveal.

How to Choose Among the Three Implementation Options

Which layer handles compression directly determines change cost and troubleshooting difficulty. Based on common delivery practices in 2026, small and medium projects mostly choose an application-layer whitelist by type, while high-traffic sites prefer to let the gateway or CDN handle it centrally, but the two approaches impose different requirements on export endpoints.

  • Disable binary compression by type at the application layer: small, controllable change, usually within an effort range of half a day to two days, with no gateway change needed, suitable for stopping the bleeding first; the cost is that every service must be configured separately.
  • Handle it centrally at the gateway and whitelist export endpoints: takes effect in one place and covers the whole site; the cost is queuing for a change, with a typical range of one to three business days, and troubleshooting has one more layer to inspect.
  • Do not compress at all: the simplest configuration; the cost is larger text-based responses and slower first screen on weak networks and mobile devices, which people can directly perceive.

The trade-off can be reduced to two points: the proportion of export endpoints among all endpoints, and whether there is centralized permission to configure the gateway. When both are satisfied, the gateway approach is more convenient; otherwise, starting with an application-layer whitelist is more prudent.

When This Applies, and When Not to Blame Compression

This approach applies to backend systems with file export or attachment download features, especially when responses pass through a gateway, CDN, or multiple proxies. One signal is enough for a judgment: the same endpoint works when connecting directly to the backend but fails through the production domain, which basically points to the intermediate chain; add 'small files work, large files are corrupted,' and the direction becomes even clearer.

Conversely, if the export already errors during generation, or the data source returns empty, template placeholders are not replaced, or cell content is too long, that has nothing to do with compression, and changing compression settings will only waste effort. For small file exports within a few hundred KB and pure text endpoints, it is usually unnecessary to set separate compression rules; in addition, a garbled filename and corrupted file content are two different things, and investigating them in the same ticket easily causes interference.

Frequently Asked Questions

After turning off gzip, the large file opens. Does that mean compression was the culprit?

Not necessarily. Turning off compression often changes buffering and output behavior along the way, and the problem may have been truncation all along. To confirm that compression itself is the cause, you still need to compare the byte count and Content-Length before and after turning it off.

If the downloaded file is a few KB smaller than expected, can I be sure it was truncated?

You can be basically sure. The actual byte count of a complete response should match Content-Length; a consistent shortfall indicates truncation, commonly caused by a timeout set too short or an output stream closed abnormally.

The export works when connecting directly to the backend locally but fails through the production domain. Where should I start looking?

Start with the intermediate chain. Local access bypasses the gateway and CDN, while online adds compression, caching, and buffer limits that may all play a role. Compare the response headers and actual byte count first; this can quickly narrow it down to a specific layer.

No line of code changed; this time there were just tens of thousands more rows exported. Why did it suddenly fail?

Because the trigger condition changed. With more rows, the file size crossed a threshold at some layer, and the buffering and timeouts that were previously sufficient are no longer enough. The problem is not new; it was simply encountered for the first time.


Next time an exported file will not open, spend ten minutes comparing the response headers and actual byte count before deciding whether to touch the compression configuration; at the same time, write the compression rules for binary downloads and the single-export size into the delivery acceptance checklist, and review them when adding a new export format. If the chain has multiple proxies and changes must go through a change process, first stop the bleeding by ruling things out at the application layer, then standardize the rules on a schedule.

Have a similar project in mind?
Contact us for a one-to-one project reference proposal
Obtain Proposal
Interested in this topic?
10-year tech team — reference proposal within 24 hours
Obtain Proposal
Are you ready?
Then reach out to us!
+86-13370032918
Discover more services, feel free to contact us anytime.
Please fill in your requirements
What services would you like us to provide for you?
Your Budget
ct.
Our WeChat
Professional technical solutions
Phone
+86-13370032918 (Manager Jin)
The phone is busy or unavailable; feel free to add me on WeChat.
E-mail
349077570@qq.com
Submitted successfully
Thank you for your trust. We will contact you soon!
Recommended projects for you