Complete and verify an API upload

Upload every multipart segment, complete the session once, recover a lost response through status, and confirm the returned file record safely.

Last reviewed

Multipart completion turns uploaded parts into a file record. It applies only when session creation returned a non-null resumable object; a small single-PUT upload finishes on its upload URL instead.

Four panels show checking uploaded part numbers, posting the multipart completion, recovering a lost receipt through status, and validating the returned file id and byte count.
Four panels show checking uploaded part numbers, posting the multipart completion, recovering a lost receipt through status, and validating the returned file id and byte count. Open full-size screenshot.

Before completion

Upload parts to PUT /api/upload/:sessionId/part/:partNumber. Part numbers start at 1 and cannot exceed total_parts. Build every nonfinal body at exactly the returned part_size; the final body must be nonempty and may be shorter. The current part size is 10 MiB, and no body may exceed that ceiling. Repeating a part number already accepted returns already_uploaded:true with the stored ETag instead of sending the bytes again.

GET /api/upload/:sessionId/status reports status, size_bytes, part_size, total_parts, bytes_uploaded, the numeric uploaded_parts array, and has_multipart. Its file_id stays null until completion succeeds.

Steps

  1. Fetch the session status and compare uploaded_parts with every number from 1 through total_parts.
  2. Resend only missing parts, preserving the exact nonfinal part_size and accepting already_uploaded:true as success for a prior retry.
  3. Call POST /api/upload/:sessionId/complete without a JSON body after every required part is present.
  4. Save the HTTP 201 response’s file.id, actual size_bytes, version, etag, name, extension, MIME type, region, and creation time.
  5. If the completion response is lost, request the status endpoint before retrying; status:"complete" and its non-null file_id recover the outcome.
  6. Fetch GET /api/files/:fileId with a read-capable credential or confirm the result in Dosya, then compare the destination, filename, and actual byte count.

Completion responses

A successful multipart completion returns content_hash:null and hash_verified:false. That Boolean means the assembled parts were not checked against a client digest; it does not mean a checksum mismatch occurred.

Dosya refuses an unknown session with Upload session not found. It returns No multipart upload in progress - upload at least one part first when no storage multipart exists, and Only X of Y parts uploaded. Upload remaining parts before completing. for an incomplete set. A repeated completion returns 409 Upload session is already complete. A stale claim can answer Upload session is no longer active - start the upload again.

A pending, uploading, or failed multipart session becomes eligible for stale cleanup after 24 hours without activity; that is not a guaranteed sweep time. Later upload initialization can schedule cleanup, and the hourly billing job runs a bounded D1-home pass. Durable Object-home sessions depend on later member activity, while the storage lifecycle aborts unfinished multipart state seven days after initiation as a backstop.

For D1-home workspaces, the billing job removes completed and failed session rows after seven days, so status-based recovery of a lost completion response is bounded by that retention window. The cited cleanup path does not establish the same row-retention period for Durable Object-home sessions; recover a lost receipt promptly while the status route still resolves. Pending rows have a separate 600-second stale cutoff in cleanup paths, and an unrenewed credential transfer slot self-heals after 15 minutes. Completion releases that slot. The final storage and database write cannot be rolled back through the upload session; subsequent removal uses the normal file trash and purge workflow.

A live same-name file can be adopted as a new version. Use a unique destination name when the requirement is a separate file.

Expected result

One HTTP 201 response identifies the completed file and reports the bytes counted from uploaded parts. A later status request returns status:"complete" and the same file identifier.

Reference for “Complete and verify an API upload”: Dosya REST API overview page with Get API Key and View SDKs links.
Reference for “Complete and verify an API upload”: Dosya REST API overview page with Get API Key and View SDKs links. Open full-size screenshot.

Was this helpful?

Loading helpfulness results…

Voting saves a necessary ballot cookie for up to 180 days so you can change your answer.

Questions and replies

Ask about the steps in this guide. Questions are reviewed before publication.

Keep account details, credentials and private files out of public questions. Use private support for those.

Loading questions…

    Sign in to your Dosya account to ask a question.

    Check the outcome before you retry

    Use these shared checks when a task needs a second look.