November 23, 2026
What Happens When You Delete a File While Itβs Uploading?
I have noticed this quite a few times. We drag a file from our desktop, drop it into a browser, and watch it upload.
By Akash Bharnuke
17 min read
But one day, a rather silly question crossed my mind.
What if I delete that original file while the upload is still in progress?
Would the upload fail? If the file is gone from my filesystem, where does the browser get the remaining bytes from?
Does the operating system somehow keep a copy of the file in memory? Does the browser already have the entire file somewhere? Or is there something happening underneath that we don't usually think about?
And that's where this rabbit hole started.
This time, I didn't want to settle for a quick search, read one Stack Overflow answer, and move on. I wanted to understand the entire journey.
From the moment we drag a file out of our filesystem, to the browser receiving it, reading its contents, and eventually sending those bytes across the network to a server.
And along the way, I wanted to understand what actually happens when that original file disappears.
So, let's follow the file.
β
So, What Actually Happens When We Drop a File?
Let's start with something we do almost every day.
We open a website, drag an image from our desktop, and drop it into an upload area.
Pretty straightforward, right?
But here's something worth thinking about: the browser doesn't magically receive the image's raw bytes just because we dropped it.
There is an interaction happening between the application we're dragging the file from (Windows Explorer, in our case), the operating system, and the browser.
The operating system facilitates the drag-and-drop interaction, and the browser receives the transferred data through its drag-and-drop APIs.
This is where a few browser APIs enter the picture.
Meet DragEvent and DataTransfer
When we drag something over a webpage, the browser fires events such as dragenter, dragover, and eventually drop.
The event contains a dataTransfer property, which gives us access to the data being transferred.
For files, we can access that through DataTransfer.files.
Let's see a small example:
const dropZone = document.querySelector("#drop-zone");
dropZone.addEventListener("dragover", (event) => {
event.preventDefault();
});
dropZone.addEventListener("drop", (event) => {
event.preventDefault();
const files = event.dataTransfer.files;
for (const file of files) {
console.log(file.name);
console.log(file.size);
console.log(file.type);
}
});const dropZone = document.querySelector("#drop-zone");
dropZone.addEventListener("dragover", (event) => {
event.preventDefault();
});
dropZone.addEventListener("drop", (event) => {
event.preventDefault();
const files = event.dataTransfer.files;
for (const file of files) {
console.log(file.name);
console.log(file.size);
console.log(file.type);
}
});Nothing too complicated here.
We're listening for the drop event, accessing the transferred files, and printing a few properties.
But notice something interesting.
We can retrieve the filename, size, and MIME type without explicitly asking JavaScript to read the entire file.
So, what exactly have we received?
Enters the File object
The browser exposes each dropped file as a File object.
At first, I was tempted to think of it as something like a JavaScript representation of the file's location on my computer.
But that's not quite the right mental model.
A File is a browser-managed representation of file data. It inherits from Blob, which represents immutable raw binary data.
We can inspect metadata through properties such as:
file.namefile.sizefile.typefile.lastModified
And when we actually want to read its contents, we have APIs such as arrayBuffer(), text(), and stream().
For example:
const file = event.dataTransfer.files[0];
// We have the File object.
console.log(file.name);
// Now explicitly request its contents.
const buffer = await file.arrayBuffer();
console.log(buffer.byteLength);const file = event.dataTransfer.files[0];
// We have the File object.
console.log(file.name);
// Now explicitly request its contents.
const buffer = await file.arrayBuffer();
console.log(buffer.byteLength);Here's the distinction I wanted to understand:
Receiving a File object and explicitly reading its contents are two different operations.
And that brings us to our next question.
When JavaScript receives this File object, what does the browser actually hold internally?
Is it holding a file path? An open file handle? A reference to some browser-managed data? Or something else entirely?
We have our first clue, but not the complete answer yet.
β
Okay, But Where Is the Actual File?
So far, we've managed to get a File object from the browser. We can inspect its name, size, type, and other metadata.
But something was still bothering me.
If JavaScript hasn't explicitly read the file contents yet, what exactly is this object holding?
Is it just the original file path? Does it contain an open file handle? Or has the browser already created some kind of internal representation that lets it access the file whenever needed?
Let's break this down.
A File isn't simply a file path
My initial mental model was something like this:
File object
|
βββ C:\Users\Admin\Desktop\profile.pngFile object
|
βββ C:\Users\Admin\Desktop\profile.pngBasically, I imagined the browser holding the file's location and using that path whenever it needed to read something.
But the browser's File API doesn't expose things that way.
A File object is an abstraction provided by the browser. JavaScript gets access to the file's data through this object, without receiving unrestricted access to the original filesystem path.
And there's another important detail: File inherits from Blob.
A little detour into Blob
A Blob (Binary Large Object) represents immutable raw binary data.
Think of it as a container representing some binary content, which could be an image, video, PDF, or practically any other type of file.
The File interface extends this functionality by adding file-related metadata such as its name and last-modified timestamp.
Conceptually:
File
|
| extends
|
Blob
|
βββ Binary data
βββ size
βββ type
βββ slice()
βββ stream()
βββ arrayBuffer()File
|
| extends
|
Blob
|
βββ Binary data
βββ size
βββ type
βββ slice()
βββ stream()
βββ arrayBuffer()One property worth highlighting is immutability.
Once we have a particular Blob representation, we cannot directly modify its contents through the Blob API.
But does that mean the browser immediately creates a complete copy of the original file?
Not necessarily.
Immutability describes the data exposed through the API. It doesn't tell us whether the browser stores that data in RAM, references disk-backed data, uses temporary storage, or implements some other mechanism internally.
And this distinction is important.
So, when does the browser actually read the contents?
Let's compare a few operations:
const file = event.dataTransfer.files[0];
// Access metadata
console.log(file.name);
console.log(file.size);
// Request the complete contents as an ArrayBuffer
const buffer = await file.arrayBuffer();
// Or consume the contents progressively
const stream = file.stream();const file = event.dataTransfer.files[0];
// Access metadata
console.log(file.name);
console.log(file.size);
// Request the complete contents as an ArrayBuffer
const buffer = await file.arrayBuffer();
// Or consume the contents progressively
const stream = file.stream();Notice that arrayBuffer() and stream() offer two different ways of consuming the contents.
With arrayBuffer(), we request the file contents as an ArrayBuffer.
With stream(), we get a ReadableStream that lets us consume the contents progressively.
This doesn't mean that accessing metadata involves absolutely no filesystem activity, or that every browser waits until arrayBuffer() is called before accessing the file.
Those are implementation details we shouldn't assume.
Here's where our original question comes back
If the browser can represent a file without exposing its original path, and can access its contents through browser-managed APIs, what happens when the original file disappears?
Does the browser already have an open reference to the underlying file?
Does the operating system preserve access to it?
Or does the browser have another way of retaining the data?
To answer that, we need to step outside the browser for a moment and understand something fundamental about how operating systems handle files.
Because here's an interesting possibility:
Deleting a file's name doesn't necessarily mean destroying the underlying file data immediately.
β
Wait, Deleting a File Doesn't Always Mean Destroying It?
Let's take a small detour.
Imagine Chrome has started reading profile.png, and halfway through the upload, I open Windows Explorer and delete that image.
My immediate assumption would be that Chrome should lose access to the file. After all, the file is gone, right?
Well, not necessarily.
To understand why, we need to distinguish between two things:
- The name through which we locate a file.
- The underlying file data managed by the filesystem.
A filename is just an entry, not the actual data
When we browse a directory, we see filenames such as:
Desktop/
|
βββ profile.png
βββ resume.pdf
βββ presentation.pptxDesktop/
|
βββ profile.png
βββ resume.pdf
βββ presentation.pptxIt's easy to think that deleting profile.png means the operating system immediately destroys everything associated with that file.
But filesystems maintain metadata and references that connect directory entries to the underlying file data.
(Yeah I mean why do you think even after delete we can undo the files back, just thought of it while proof reading this blog).
For example, in filesystems such as Linux's ext4, a directory entry maps a filename to an inode.
The inode contains metadata about the file and references to its data blocks.
Conceptually:
Desktop/
|
βββ profile.png
|
v
Inode
|
v
File DataDesktop/
|
βββ profile.png
|
v
Inode
|
v
File DataThe important distinction is that the directory entry and the underlying file data have separate lifecycles.
Removing the directory entry doesn't necessarily mean the underlying data must become inaccessible immediately.
And Linux gives us a particularly interesting example of this.
Let's talk about Linux and unlink()
Linux provides the unlink() system call to remove a name from the filesystem.
Consider this simplified example:
int fd = open("profile.png", O_RDONLY);
// Remove the filename
unlink("profile.png");
// Continue reading through the existing descriptor
read(fd, buffer, sizeof(buffer));
// Close the file
close(fd);int fd = open("profile.png", O_RDONLY);
// Remove the filename
unlink("profile.png");
// Continue reading through the existing descriptor
read(fd, buffer, sizeof(buffer));
// Close the file
close(fd);Something interesting happens here.
Even after unlink() removes the filename, the process can continue reading through its already-open file descriptor.
Why?
Because the operating system still maintains the underlying file while it has relevant references to it.
The file's storage can be reclaimed once the last relevant reference is gone.
So, we have an important distinction:
The filename can disappear while an already-open application still has access to the underlying data.
And no, the operating system doesn't need to copy the entire file into RAM to make this possible.
But Windows works a little differently
Since our original experiment involves Windows, we can't simply take Linux behaviour and assume Windows works the same way.
Windows uses file handles and has explicit file-sharing rules.
When an application opens a file, it can specify whether other applications are allowed to:
- Read the file.
- Write to the file.
- Delete or rename the file.
These sharing permissions matter.
Depending on how the file was opened and how deletion is requested, Windows may:
- Reject the deletion because another application has the file open.
- Allow deletion while an existing handle remains open.
- Mark the file for deletion and complete removal after relevant handles are closed.
(Yes like we can't delete/move an open file being used in any other running application.)
So, unlike our simplified Linux example, we need to consider Windows sharing modes and deletion semantics.
Now, let's connect this back to Chrome
We have discovered something important.
An application doesn't necessarily need the original filename to remain present in the directory to continue accessing a file it already opened.
But hold on.
We still haven't established exactly how Chrome handles a dropped file internally.
Does it retain an open file handle? Does it use another browser-managed mechanism? When is that access established?
The File API doesn't prescribe one universal internal implementation.
And that's why we shouldn't jump to the conclusion that every browser will behave identically when we delete the original file.
But at least we now understand one important piece of the puzzle:
Deleting a file and losing access to its contents are not necessarily the same event.
And this raises another question.
If the operating system can preserve access to file data without loading the entire file into memory, how does it actually manage those bytes?
That's where memory management, page caching, and buffering enter our story.
β
Does the Browser Load the Entire File Into RAM?
Let's imagine we're uploading a 2 GB video.
The file is sitting on our SSD, and the browser needs to read its contents and send them to a server.
My first thought was: does the browser load the entire 2 GB file into RAM before starting the upload?
That would be quite wasteful, wouldn't it?
Imagine uploading a 10 GB file and needing another 10 GB of available memory just to get the job done.
Fortunately, that's not how file access has to work.
To understand what's happening, we need to look at two things: the operating system's page cache and application-level buffering.
First, what's this Page Cache?
Operating systems don't necessarily fetch data from storage every time an application requests it.
They use available memory to cache filesystem data.
On Linux, this is commonly known as the Page Cache.
Here's the basic idea:
- An application requests some data from a file.
- The operating system retrieves the required data from storage.
- The data can be retained in RAM through the page cache.
- If the same data is requested again, the OS may serve it from memory instead of reading it from storage again.
Think of it as the operating system keeping recently accessed file data readily available.
And here's something important: the page cache doesn't mean the entire file must be loaded into memory.
The OS can cache portions of a file as they're accessed. Cached pages can also be reclaimed when memory pressure requires it.
So, if we're uploading a 2 GB video, the OS doesn't necessarily need to cache all 2 GB at once.
But what about Application Buffers?
Now let's move one layer up.
Even if the OS handles storage access efficiently, applications still need temporary memory to process the data they're reading.
That's where buffers come in.
A buffer is simply a temporary memory area used to hold data while an application processes or transfers it.
For example, consider this Python code:
with open("video.mp4", "rb") as file:
while chunk := file.read(1024 * 1024):
upload_chunk(chunk)with open("video.mp4", "rb") as file:
while chunk := file.read(1024 * 1024):
upload_chunk(chunk)What's happening here?
- We open a 2 GB file.
- We read 1 MB at a time.
- That chunk is passed to our upload operation.
- We repeat until the file is exhausted.
We're not explicitly loading the entire 2 GB file into one Python object.
Instead, we're processing smaller portions.
Of course, the operating system may independently cache some of the file data in RAM.
So, we now have two different concepts:
- Page Cache: Managed by the operating system.
- Application Buffer: Managed by the application.
They're related, but they're not the same thing.
Okay, But How Does JavaScript Handle This?
Remember our File object from earlier?
It provides a method called stream().
const file = event.dataTransfer.files[0];
const stream = file.stream();const file = event.dataTransfer.files[0];
const stream = file.stream();This gives us a ReadableStream, which allows us to consume the file's contents progressively.
For example:
const file = event.dataTransfer.files[0];
const reader = file.stream().getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
console.log("Received bytes:", value.byteLength);
}const file = event.dataTransfer.files[0];
const reader = file.stream().getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
console.log("Received bytes:", value.byteLength);
}Instead of explicitly requesting one giant ArrayBuffer, we're reading the contents incrementally.
This is particularly useful when dealing with large files.
But there's one more concept worth understanding here.
What Happens When the Reader Is Faster Than the Network?
Suppose our file reader can provide data at 100 MB/s, but our network can only transmit 10 MB/s.
The producer is generating data much faster than the consumer can process it.
If we keep reading without controlling the flow, temporary buffers could grow unnecessarily.
This is where Backpressure comes into play.
Backpressure is a mechanism through which a slower consumer can influence how quickly a producer supplies more data.
In the context of streams, it helps regulate data flow and prevents uncontrolled buffering.
However, we shouldn't assume that every browser upload uses a particular chunk size or has a fixed memory limit. Those details depend on the implementation and the APIs involved.
One Last Thing: Does Streaming Mean Zero Memory Usage?
Not at all.
Streaming doesn't mean the file magically travels from SSD to network without occupying memory.
We still have:
- OS-managed page caches.
- Browser-managed buffers.
- Individual stream chunks.
- Network transmission buffers.
- Other internal processing.
The difference is that we don't necessarily need to materialize the entire file in application memory at once.
And that's a pretty important distinction.
We can now understand how an application might continue reading file data without requiring the entire file to be copied into RAM.
But we're still missing the final part of the journey.
We've got the file, we've accessed its contents, and we've discussed how those bytes are handled in memory.
So how do they actually leave the browser and reach the server?
β
From Our Browser to the Server: How Does the Upload Actually Happen?
Okay, so we have a file, and the browser can access its contents.
Now let's say we're building a simple upload feature. We want to send that image to our backend.
How do we actually do that?
If you've worked with frontend development, you've probably used FormData and fetch() before. But have you ever wondered what happens to the file between those two?
Let's take a closer look.
First, Meet FormData
Suppose we've received our file:
const file = event.dataTransfer.files[0];const file = event.dataTransfer.files[0];We can attach it to a FormData object:
const formData = new FormData();
formData.append("image", file);const formData = new FormData();
formData.append("image", file);That's it.
We've added our file to a form-data container.
But here's something I found interesting: we haven't manually converted the file into Base64, turned it into a string, or explicitly created a complete in-memory copy using arrayBuffer().
We're passing the File object directly.
The browser handles the representation of that file when constructing the request body.
But What Does Multipart/Form-Data Actually Look Like?
This is where things get a little more interesting.
When we upload files using FormData, browsers commonly encode the request body using multipart/form-data.
The name itself gives us a clue: the request body is divided into multiple parts.
Imagine we're sending two things:
- A username:
Akash - An image:
profile.png
The resulting HTTP request is conceptually structured like this:
POST /upload HTTP/1.1
Host: example.com
Content-Type: multipart/form-data; boundary=----UploadBoundary
------UploadBoundary
Content-Disposition: form-data; name="username"
Akash
------UploadBoundary
Content-Disposition: form-data; name="image"; filename="profile.png"
Content-Type: image/png
[Binary image data]
------UploadBoundary--POST /upload HTTP/1.1
Host: example.com
Content-Type: multipart/form-data; boundary=----UploadBoundary
------UploadBoundary
Content-Disposition: form-data; name="username"
Akash
------UploadBoundary
Content-Disposition: form-data; name="image"; filename="profile.png"
Content-Type: image/png
[Binary image data]
------UploadBoundary--Notice the boundary.
It's a separator used to distinguish individual parts of the multipart request.
Each part can have its own headers and content.
Our username is represented as a regular form field, while the image is transmitted as binary data.
And importantly, the image doesn't need to be converted into readable text before being uploaded.
Now, Let's Actually Send It Using fetch()
Here's how our upload might look:
const formData = new FormData();
formData.append("image", file);
const response = await fetch("/upload", {
method: "POST",
body: formData
});
console.log(await response.json());const formData = new FormData();
formData.append("image", file);
const response = await fetch("/upload", {
method: "POST",
body: formData
});
console.log(await response.json());Pretty straightforward.
But there's one small detail worth remembering.
Notice that we haven't manually specified the Content-Type header.
That's intentional.
When sending FormData, the browser generates the multipart boundary and includes it in the appropriate header.
If we manually set Content-Type: multipart/form-data without the matching boundary, the server may not be able to parse the request correctly.
So, What Happens After fetch()?
Once we call fetch(), the browser takes responsibility for constructing and processing the request.
At a high level, the journey looks something like this:
File Object
|
v
FormData
|
v
fetch() API
|
v
Browser Networking
|
v
HTTP Request
|
v
Network
|
v
Backend Server
|
v
File ProcessingFile Object
|
v
FormData
|
v
fetch() API
|
v
Browser Networking
|
v
HTTP Request
|
v
Network
|
v
Backend Server
|
v
File ProcessingThe browser handles the networking details internally.
We don't need to manually read every byte and write it to a socket ourselves.
The browser takes care of the request and its transmission.
But What If the Network Is Slower Than the File Reader?
Remember our earlier discussion about backpressure?
Let's bring that back.
Imagine the browser can read data from the file much faster than the network can transmit it.
If data is continuously produced faster than it can be consumed, temporary buffers could accumulate.
This is why controlling data flow matters.
However, we should be careful about making assumptions here.
Using FormData with fetch() doesn't give us a guarantee about the exact internal chunk size, buffering strategy, or memory consumption used by every browser.
Those are implementation details.
One More Interesting Thing: Does fetch() Automatically Resume Uploads?
Imagine we're uploading a 2 GB video.
The network connection drops after 1.5 GB has been transmitted.
Can the browser simply reconnect and continue from where it stopped?
Not automatically.
A regular fetch() request doesn't provide resumable-upload semantics by itself.
If we want resumability, the application and server need additional support to track uploaded portions and continue from an appropriate checkpoint.
This is why large-file upload systems often implement dedicated resumable-upload protocols.
So, We've Finally Reached the Server
Our file has travelled from a local filesystem, through browser-managed APIs, into an HTTP request, and eventually to a backend.
But here's something worth remembering:
The server receiving the bytes and the client knowing that the upload succeeded are two different things.
The server might have already received some data before the connection fails. It might even have received and stored the complete file before the client receives the final response.
We'll come back to this distinction when we explore failure scenarios.
For now, we've completed the journey from our browser's File object to the server receiving the upload.
β
Okay, But What Happens When Things Go Wrong?
We've covered quite a bit so far.
We know that a browser exposes a File object, that the operating system manages file access, that data can be read progressively, and that the browser eventually sends it through an HTTP request.
But what happens when we interrupt this process?
Let's revisit a few scenarios.
Scenario 1: What If I Delete the File Immediately After Dropping It?
Let's say:
- I drag
profile.pnginto Chrome. - Chrome exposes a
Fileobject. - Before the upload even starts, I delete the original file.
- JavaScript then attempts to upload it.
Will it work?
We cannot give a universal guarantee here.
Receiving a File object doesn't necessarily mean the browser has already copied the entire file into memory.
Whether it can still read the contents depends on how the browser manages access to the underlying file and how the operating system handles the deletion.
This is exactly why we shouldn't assume that Linux's open-file behaviour automatically describes Chrome on Windows.
Scenario 2: What If I Delete the File Halfway Through the Upload?
This is even more interesting.
Imagine we're uploading a 500 MB file, and we've already transmitted 250 MB.
Now I delete the original file.
What happens to the remaining 250 MB?
If the browser still has valid access to the underlying file data, it may continue reading and uploading.
If that access is lost, the remaining read operation may fail, potentially causing the upload to fail.
The important distinction is that the first 250 MB may already have reached the server, but that doesn't mean the complete upload has succeeded.
Scenario 3: What If I Rename or Move the File?
This is slightly different from deleting it.
Renaming a file generally changes its directory entry rather than creating an entirely new file.
Similarly, moving a file within the same filesystem may simply change its directory location.
An already-established file reference may continue working even though the original pathname has changed.
However, moving across filesystems can involve copying the file and deleting the original.
So, we shouldn't treat every move operation as equivalent.
Scenario 4: What If I Modify the Original File During Upload?
This is one of the scenarios I find particularly interesting.
Imagine:
- Chrome receives a
Fileobject. - Upload begins.
- Another application modifies the original file.
- Chrome continues reading it.
Will the uploaded file contain the original contents or the modified contents?
We shouldn't automatically assume that the browser provides a snapshot of the original file at drop time.
The Blob API describes immutable data, but that doesn't establish the exact timing and mechanism through which a browser obtains the underlying file contents.
The behaviour needs to be verified for the browser and operating system involved.
Scenario 5: What If I Close the Browser Tab?
Now let's move away from filesystem behaviour.
Suppose an upload is running through JavaScript using fetch(), and I close the tab.
The page's execution context is terminated, and its in-progress request generally won't continue as an ordinary page-initiated upload.
But here's another distinction.
The server may already have received some or even all of the uploaded data.
Closing the tab doesn't automatically roll back work the server has already performed.
For example, the backend might have already written the uploaded file to temporary storage.
So:
The client stopping an upload doesn't necessarily mean the server has undone everything it received.
Scenario 6: What If the Network Disconnects?
Let's say we're uploading a 500 MB file, and the network connection disappears after 300 MB has been transmitted.
What happens now?
A conventional HTTP upload doesn't automatically resume from the last successfully transmitted byte.
Depending on the server implementation:
- The request may fail.
- The server may have received only part of the file.
- Temporary data may be retained or discarded.
- The application may need to retry the upload.
This is why resumable uploads require additional client-server coordination.
The server needs a way to identify what has already been received and where the next upload should continue.
One Important Distinction Across All These Scenarios
There are actually three different layers involved in these failures:
1. Operating system: Can the browser continue accessing the original file data?
2. Browser: Can it continue reading the file and supplying data to the request?
3. Server: Has it received and successfully persisted the complete upload?
A failure at one layer doesn't automatically tell us what happened at the other two.
And that's probably the most useful mental model we've developed throughout this investigation.
β
So, Will Deleting the File Actually Break the Upload?
The short answer: Not necessarily.
By the time you delete the file, a few different things might already have happened:
- The browser may have read some or all of the file.
- Some bytes may already be buffered in memory or other internal storage.
- The operating system may still allow access to the underlying file data, even after its original filename is removed.
- Some bytes may already have reached the server.
But there's an important catch: the browser isn't required to load the entire file into memory when you drop it. It may still need to read more data as the upload progresses.
If that access becomes unavailable before the browser has read everything, the upload can fail. And the exact outcome depends on how the browser accesses the file and how the operating system handles its deletion.
So, deleting a file isn't automatically equivalent to pulling the plug on an ongoing upload.
The filename, the underlying file data, the browser's File object, the bytes already read, and the bytes already sent over the network are different pieces of the process.
And that's what makes this seemingly simple action more interesting than it first appears.
And finally I got a somewhat answer to my long lasted question and now I can sleep in peace.
I will be back with something unusal as well so till thenβ¦
Peace Outβ¦