Key takeaways
- A multipart form packages fields and files into one body; it does not define resumability.
- A part-based upload needs an upload identifier, accepted parts, and a completion operation.
- tus resumes from a server-confirmed offset, while the application still tracks processing.
“Multipart” can name a request body or a protocol that transfers one object in several parts. Those meanings have different completion and retry rules. Before choosing a library, identify who receives the bytes, what state survives an interruption, and what event makes the upload complete.
Start with what the upload endpoint accepts
multipart/form-data packages named fields and files in one request body. Multipart upload divides one object into parts that the storage service records separately. tus lets a client resume from an offset confirmed by the server. Check which method your endpoint accepts before choosing a client library: all three can carry a large file, but they have different retry rules.
The destination is a separate choice. A direct-to-cloud upload sends bytes to storage without passing them through your application server. It can use one request or many parts. Decide where the file goes and what progress the receiving service records; those details tell you whether an interrupted transfer can continue.
Small form submission
An avatar plus a display-name field can fit naturally in one multipart form request. If the request is interrupted, the application needs a deliberate retry policy rather than assuming the file resumes.
Large recording
A recording sent over an unreliable connection benefits from an acknowledged offset or part list. The important property is retained server state, not whether the UI draws a progress bar.
Use FormData only with an endpoint that accepts its fields
A multipart form can send one file, several files, and ordinary fields together. A generated boundary separates the parts, and each part identifies its field name. Use the names your endpoint expects: sending file will not work if the server expects attachment. The server still needs to validate uploaded content because the sender can choose the filename and declared type.
For an existing endpoint, the helper below sends one selected file and rejects readable HTTP failures. Keep the endpoint’s authorization and CSRF requirements when adapting it. Fetch sends cookies to same-origin endpoints by default; a credentialed cross-origin contract needs explicit credentials and matching server CORS configuration. A successful response still needs the API’s success validation: a login redirect can end in 200 without accepting a file. Let FormData supply Content-Type.
async function sendFile(file: File, endpoint: URL): Promise<Response> {
const body = new FormData()
body.append('file', file)
const response = await fetch(endpoint, { method: 'POST', body })
if (!response.ok) {
throw new Error(`Upload returned HTTP ${response.status}`)
}
return response
}Track initiation, parts, and completion for object storage
S3 creates an upload identifier before receiving numbered parts. The client records the accepted part information and sends an ordered completion request when all required parts are available. Concurrent transfers can improve throughput, but they also increase in-flight work and complicate cancellation. Part size, permitted counts, checksums, signing, and expiry come from the chosen service’s contract, not a universal multipart rule.
Retain the upload identifier, object key, and your own accepted part numbers and ETags. When reconnecting, use service listings to verify progress; AWS cautions against building the completion request from a ListParts result. A lost acknowledgement may mean the part was stored successfully. Verify the final object and its intended identity after completion. Configure abort and lifecycle cleanup for abandoned uploads because retained parts can consume storage even though no completed object is visible to the application.
Let the server’s tus offset decide where bytes resume
A tus client learns the server’s accepted Upload-Offset through HEAD and supplies an expected offset when appending data with PATCH. That precondition prevents a stale local progress counter from deciding where the next bytes belong. If a response disappears, the client queries the upload resource before continuing. The core append model is sequential; optional extensions provide additional capabilities under their own negotiation rules.
Store the resource URL where the client can recover it, and retain or reacquire the same source file. A saved URL cannot recreate file bytes after the user closes the page. Expiry, authorization, and application job lifetime can also end a resumable session. Use a maintained tus client where practical, and test recovery in the browsers and persistence environment the product actually supports.
Configure CORS and recover after lost responses
Configure CORS on the upload service for the browser’s origin, methods, and request headers. Expose the response headers your client reads: S3 clients need part ETag values, and tus clients read Upload-Offset after HEAD and PATCH responses, and Upload-Length when resuming. The tus Creation extension returns the new resource URL in Location. Follow your client library’s full CORS configuration and check error responses too. A command-line upload can work while the browser is unable to read its response.
After a timeout, the server may already have accepted the file, part, or completion request. Query its progress before retrying an operation that could create a duplicate. Where the API supports idempotency, use a stable identifier for the operation so a retry can refer to the same work. Show an explicit rejection differently from a request whose result is still unknown.
Test transfer completion separately from usable application output
Exercise interruption during the body, after a part is accepted, and after the final bytes arrive but before the completion response reaches the client. Confirm the recovered state against the server and verify final content integrity. Also test cancellation and an expired session. Observe which retained identifiers let the system continue, which require a new upload, and how abandoned work is cleaned up.
Once the transfer finishes, show the phase the user is waiting for: validation, encoding, storage, or publication. An uploaded video can still fail decoding, and an encoded result can fail export. When using Transloadit, associate the Assembly ID with your application’s file record and check the processing result before making the file available.
Technical details worth knowing
- RFC 7578 defines multipart/form-data as a representation with boundary-delimited parts, not independently acknowledged network transfers.
- A browser serializing FormData supplies the matching Content-Type boundary; setting that header manually can make the body unreadable.
- Amazon S3 multipart upload creates an object through initiation, numbered part uploads, and a final completion request.
- The core tus protocol uses HEAD to discover the accepted Upload-Offset and PATCH to append bytes with an offset precondition.
- A browser CORS failure can hide a response even after the server accepted the bytes, so inspect authoritative state before retrying.
- Completing a transfer does not establish that validation, encoding, export, or application publication has succeeded afterward.
A practical approach
- 1
Check whether the receiving endpoint accepts form requests, storage parts, or tus before choosing a client.
- 2
Define what identifiers and source-file access the client must retain after an interruption.
- 3
Test a lost response, a failed part, cancellation, and expiry against the real upload service.
- 4
Confirm final transfer state, then track processing and publication as separate application states.
When Transloadit is useful
Uppy supports several upload backends, including S3-compatible storage and tus. Transloadit accepts files in a multipart/form-data Assembly creation request or through a separate tus transfer after creation. Files in an interrupted creation request cannot be resumed through that form request. Choose the integration that matches the destination and follow its documented completion signals.
Architecture boundary
Resuming after a browser restart requires both saved upload state and access to the same source file. A saved upload URL or part list cannot recover a local file the browser can no longer read.
Frequently asked questions
Does multipart/form-data resume a failed request?
No resumability is defined by that body format. A receiver could build a separate resume mechanism, but sending a multipart form alone does not establish one. Check the endpoint’s documented transfer state and retry contract.
Can a direct upload still use multipart parts?
Yes. Direct describes the byte path from the client to the service, while multipart describes independently tracked pieces. Uppy’s S3 integration is an example where the browser can send parts directly to storage using scoped authorization.
Does tus keep uploading after the tab closes?
The protocol defines how a client can resume while its upload resource remains usable. It does not keep a closed browser page executing or guarantee access to the local source file after a restart.
Is an S3 ETag always the complete file’s MD5?
No. Its interpretation depends on how the object was created and other service details. In particular, multipart objects need not have a full-file MD5 ETag. Use the documented checksum mechanism instead of inferring integrity from that field.