Stream an API download to disk
Follow Dosya’s guarded download redirect without forwarding the API key, stream storage bytes to disk, and validate the saved file against metadata.
Last reviewed
The standard download route authorizes the request, then returns HTTP 302 to a five-minute presigned storage URL. The raw route stays on Dosya and supports byte ranges. These are distinct contracts; a 302 response is not itself a file stream.

Before you start
- A read-scoped API key is sufficient, but the workspace role must expose the Files page and include
download_files. - Know the file ID. Add
version=Nfor a previous version orut=tokenonly when your flow received an unlock token. - Write to a temporary local path so an interrupted response never replaces a known-good file.
Steps
- Fetch metadata first and record the expected name and size. Refuse the job if the selected version or unlock context is not the one the caller intended.
- Request
GET /api/files/file_id/downloadwithout automatic redirect handling. Require 302 and readLocation; the signed URL normally expires after 300 seconds. - Open
Locationas a separate request withoutAuthorizationor the Dosya API key. Stream response chunks into the temporary file instead of buffering the full object. - Alternatively, call
GET /api/files/file_id/download-url; its JSON containsurl,size,name, andregion. A requested TTL defaults to 300 seconds and is capped at 3600. - For resumable byte transfer, use
GET /api/files/file_id/rawwithRange: bytes=start-. Expect 206 andAccept-Ranges; a range outside the object returns 416. - After the stream closes, compare bytes written with metadata or the download-url
size. Rename the temporary file into place only after validation.

Expected result
The client stores the complete object without exposing its API credential to the storage host. A full download matches the expected byte count; a resumed raw request returns the correct remaining range.
Troubleshooting
The first response is 302. That is the standard route’s success contract. Follow Location in a credential-free request.
The signed URL expired. Request a new URL after reauthorizing; do not edit its query string.
The raw request returns 416. Compare the local partial size with the current remote size. Restart when the partial file exceeds or belongs to another version.
Related guides
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.