Create a REST API upload session

Start a REST API upload with the correct destination, size, scope, and multipart settings, then inspect the returned session before sending bytes.

Last reviewed

Create an upload session only after the destination and credential boundaries are known. The REST base is https://api.dosya.dev/api, and requests authenticate with Authorization: Bearer dos_….

Four panels show choosing a workspace and folder, posting upload-init fields, checking the 201 session, and branching to single PUT or 10 MiB multipart transfer.
Four panels show choosing a workspace and folder, posting upload-init fields, checking the 201 session, and branching to single PUT or 10 MiB multipart transfer. Open full-size screenshot.

Requirements

Use an Upload only or Full access key that permits the REST API surface. A workspace pin is compatible with REST; a folder anchor is not. Folder-anchored keys are rejected before the upload route runs.

An ordinary REST upload requires both upload_files and access_upload in the current workspace role. Only the SFTP gateway bypasses the upload-page gate because its separate access_sftp permission governs that surface. Dosya can answer You don't have upload permission in this workspace or You don't have access to the upload page when either REST role gate fails.

Steps

  1. Choose the destination workspace and, when the file belongs below a folder, record that folder’s fld_… identifier.
  2. Send POST /api/upload/init with JSON containing workspace_id, file_name, and the byte value file_size; add folder_id only for a non-root destination.
  3. Add mime_type when known. It defaults to application/octet-stream; file_id and expected_version are for deliberate version replacement, while force_multipart must be a Boolean.
  4. Check the 201 response for the same workspace, sanitized filename, declared size, MIME type, extension, region, and a new session_id.
  5. Read resumable: null means send one PUT to upload_url; an object means use its part_upload_url, complete_url, and status_url values.
  6. Store the session details beside the local transfer state, then begin sending bytes only after the returned destination and transfer mode match the intended upload.

Request rules and limits

A filename is sanitized before validation and may contain at most 255 characters. Supply an accurate numeric file_size; omission is treated as zero, and a negative value is refused. expected_version, when present, must be a non-negative integer. force_multipart:true requires a file larger than zero bytes.

Files above 50 MiB use multipart automatically. A smaller file can opt in with force_multipart:true. Multipart sessions use 10 MiB parts and report total_parts; smaller ordinary sessions return resumable:null.

Initialization also checks storage quota, the credential’s maximum file size, workspace extension and size policies, per-member storage, the destination folder, locks, and concurrency. There is no separate Idempotency-Key header for this endpoint.

Expected result

The API returns HTTP 201 with ok:true, a unique session_id, upload_url, normalized file details, and either a multipart instruction object or resumable:null. No file is complete merely because the session exists.

Troubleshooting

workspace_id is required, file_name is required, and file_size must not be negative identify malformed input. force_multipart must be a boolean and force_multipart requires a file_size greater than 0 explain multipart setup errors. A 403 mentioning a folder anchor means the key must be recreated without that REST-incompatible restriction.

Reference for “Create a REST API upload session”: Dosya REST API overview page with Get API Key and View SDKs links.
Reference for “Create a REST API upload session”: 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.