Use idempotency keys for API uploads

Protect one-shot uploads with a UUID-v4 idempotency key, distinguish replay from in-flight work, and reject accidental reuse for different bytes.

Last reviewed

Dosya idempotency applies to the one-shot PUT /api/upload/file route. Send a UUID-v4 value in X-Dosya-Idempotency-Key; multipart session routes have their own part-number resume contract.

Four workflow panels show binding one UUID-v4 key, retaining the first 201 receipt, recognizing an identical replay, and stopping when a key was reused.
The diagram covers binding one UUID-v4 key, retaining the first 201 receipt, recognizing an identical replay, and stopping when a key was reused. Open full-size screenshot.

Before you start

  • Generate one fresh UUID v4 for one logical upload and persist it with that job until the result is verified.
  • Keep workspace, folder, raw filename, and Content-Length unchanged across retries; these values form the request fingerprint.
  • The request body must be replayable before automatic retry is enabled.

Steps

  1. Create a UUID v4 such as 3fa85f64-5717-4562-b3fc-2c963f66afa6 and associate it with the local source path and intended destination.
  2. Send PUT /api/upload/file?file_name=report.pdf&folder_id=folder_id with the exact Content-Length, bearer key, body, and X-Dosya-Idempotency-Key.
  3. On HTTP 201, store the returned file receipt. The server retains a completed idempotency record for 86,400 seconds, so a matching retry can recover the response.
  4. After an ambiguous transport failure, repeat the identical request with the identical key. HTTP 200 plus X-Dosya-Idempotent-Replay: true means Dosya returned the earlier result without a second file.
  5. For HTTP 409 with Retry-After: 5, another matching request is still in progress. Wait and retry; abandoned in-progress ownership can be taken over after 600 seconds.
  6. For 409 with code idempotency_key_reused, stop. The key was paired with a different workspace, folder, raw filename, or declared length; generate a new key only for a genuinely new upload.
Dosya developer overview with API and SDK entry points for use idempotency keys for api uploads.
The developer overview supplies the API and SDK entry points referenced by “Use idempotency keys for API uploads”. Open full-size screenshot.

Expected result

The first accepted upload returns 201. An identical replay returns the same logical result with status 200 and the replay header, while a mismatched fingerprint is refused rather than creating uncertain data.

Troubleshooting

The body cannot be replayed. Spool it to a temporary file before the first request or disable automatic retries.

The response is 409 without the reuse code. Honor Retry-After: 5; do not create a new key while the original operation may still finish.

The file bytes changed but length did not. Use X-Dosya-Sha256 as an integrity check and a new idempotency key for the new logical upload.

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.