Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Ajax

Ajax: Fix a File Upload That Silently Fails Only for Files Over a Certain Size

- 05.09.26 - ErcanOPAK

🔄 Small Files Upload Fine – Anything Over a Certain Size Just Vanishes

A file upload form works perfectly in testing with small sample files, and once real users start uploading anything past a certain size, the request appears to complete (no visible error, the spinner stops) while the file itself never actually shows up on the server.

🐞 The Problem

const formData = new FormData();
formData.append('file', fileInput.files[0]);

fetch('/api/upload', { method: 'POST', body: formData })
  .then(res => {
    if (res.ok) showSuccess(); // fires even when nothing was saved!
  });
// No response.ok check catches a server-side silent rejection
// that still happens to return a 200-range status.

🔍 Why This Happens

Multiple layers between the browser and your application code can
each enforce their OWN maximum request/body size independently - the
web server (IIS, nginx), the framework's own default limit
(ASP.NET Core's default 30MB Kestrel limit, PHP's upload_max_filesize),
and a reverse proxy or CDN in front of it all. Depending on which
layer rejects an oversized file, the response can come back as a
generic error the client-side code doesn't specifically check for,
or in some misconfigurations, as a deceptively success-looking
response with an empty or truncated body.

✅ The Fix: Check the Response Explicitly, and Align Every Layer’s Limit

  • Never assume a fetch that resolves without throwing means success – always explicitly check response.ok and, ideally, the actual response body/status, not just that the network request itself completed without an exception.
  • Identify every layer’s size limit (server framework, reverse proxy, CDN, load balancer) and raise them CONSISTENTLY to match your real maximum intended file size – the smallest limit in the chain is the one that actually applies, regardless of how generous the others are.
  • Show the user a clear, specific error when a file is rejected for size (‘Files must be under 50MB, this file is 120MB’) rather than a generic failure – this alone eliminates most confusion even before the underlying limits are fully sorted out.

📦 Correct Version (Explicit Response Checking)

fetch('/api/upload', { method: 'POST', body: formData })
  .then(async res => {
    if (!res.ok) {
      const message = await res.text();
      showError(`Upload failed: ${message || res.status}`);
      return;
    }
    showSuccess();
  })
  .catch(() => showError('Upload failed - check your connection.'));

A request that finishes without throwing was never a guarantee it succeeded — between the browser and your server sit several independent size limits, and any one of them can quietly swallow the file you thought had arrived.

— Frontend Engineer

Related posts:

Ajax: Fix an AbortController Cancellation That Shows an Error Message Because the Catch Block Can't ...

Ajax: Fix an AbortController Cancellation That Shows an Error Message Because the Catch Block Can't ...

AJAX: Use fetch() timeout with AbortController

AJAX: Use fetch() timeout with AbortController

Silent JSON Parsing Failures

Silent JSON Parsing Failures

Views: 19
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Photoshop: Fix a Font That Displays as a Different Typeface When You Reopen the File Elsewhere
WordPress: Fix a Site That Sends Two Copies of Every Notification Email

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 868 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com