Download a file
Signed URL from an export/url task. No API key needed. The answer is the file or a 302 to a short-lived URL of the file.
GET
https://api.switchfile.io/files/{fileId}/{filename}Example
Request
curl -L "https://api.switchfile.io/files/2a6f8e1c-4b3d-4e7a-9c5f-8d1b0e2a4c67/report.pdf?expires=1762538401&signature=3f9c2a7d41e8b6c05d1f9e2a7b4c8d3e6f0a1b2c3d4e5f60718293a4b5c6d7e8" \
-o report.pdfimport { writeFile } from "node:fs/promises";
const res = await fetch("https://api.switchfile.io/files/2a6f8e1c-4b3d-4e7a-9c5f-8d1b0e2a4c67/report.pdf?expires=1762538401&signature=3f9c2a7d41e8b6c05d1f9e2a7b4c8d3e6f0a1b2c3d4e5f60718293a4b5c6d7e8");
if (!res.ok) throw new Error(`HTTP ${res.status}`);
await writeFile("report.pdf", Buffer.from(await res.arrayBuffer()));<?php
$ch = curl_init('https://api.switchfile.io/files/2a6f8e1c-4b3d-4e7a-9c5f-8d1b0e2a4c67/report.pdf?expires=1762538401&signature=3f9c2a7d41e8b6c05d1f9e2a7b4c8d3e6f0a1b2c3d4e5f60718293a4b5c6d7e8');
curl_setopt_array($ch, [
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status >= 400) {
throw new RuntimeException("HTTP $status: $response");
}
file_put_contents('report.pdf', $response);import requests
res = requests.get(
"https://api.switchfile.io/files/2a6f8e1c-4b3d-4e7a-9c5f-8d1b0e2a4c67/report.pdf?expires=1762538401&signature=3f9c2a7d41e8b6c05d1f9e2a7b4c8d3e6f0a1b2c3d4e5f60718293a4b5c6d7e8",
allow_redirects=True,
)
res.raise_for_status()
with open("report.pdf", "wb") as f:
f.write(res.content)Parameters
Path parameters
fileIdstring (uuid)requiredID of the file
filenamestringrequiredFile name
Query parameters
expiresnumberrequiredPart of the signed URL
example: 1762538401
signaturestringrequiredPart of the signed URL
at least 1 characters · example: 3f9c2a7d41e8b6c05d1f9e2a7b4c8d3e6f0a1b2c3d4e5f60718293a4b5c6d7e8
inlinestring1: show the file in the browser instead of downloading it
one of "1"
Responses
- 200The file
- 302Redirect to a short-lived URL of the file
403The signature is wrong or the link has expired
EXPIRED403 application/json{ "message": "The download link has expired.", "code": "EXPIRED" }404The file was deleted
NOT_FOUND404 application/json{ "message": "File not found.", "code": "NOT_FOUND" }422Invalid data. errors names the fields
INVALID_DATA422 application/json{ "message": "id: Expected string to match 'uuid' format", "code": "INVALID_DATA", "errors": { "id": [ "Expected string to match 'uuid' format" ] } }