Skip to content

Upload and download

By , Head of IntegrationsUpdated

Open this page in a new chat

Short answer

Upload a file by sending its bytes to POST /v2/files/upload with the path it should have; missing folders are created for you. Fetch copies a file from any URL into your account. For very large files, use resumable tus uploads. Download returns the original file. Each command needs a bearer token.

After reading this you will know

  • How to upload a file, or fetch one from a URL
  • How to upload large files with resumable tus uploads
  • How to download the original of any file

Every command on this page needs a bearer token.

GEThttps://api.sirv.com/v2/files/download

Use this API method to download a single file from an account.

Query parameters

NameTypeRequiredExampleDescription
filenamestringYes/REST API Examples/uploaded.txtPath of the file to download.

Example request

// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/files/download?filename=%2FREST%20API%20Examples%2Fuploaded.txt', {
method: 'GET',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },
});
console.log(res.status, await res.text());

Response

HTTP 200 with an empty body when the command succeeds.

POSThttps://api.sirv.com/v2/files/fetch

Use this API method to fetch a file(s) from a URL via HTTP and save it to your Sirv account.

This can be any URL, either public or private (via HTTP authentication). In the url parameter, enter the full URL of the remote file.

In the filename parameter, enter the folder path and filename where it should be saved e.g. /path/to/folder/new-filename.jpg.

If the folder path does not already exist in your Sirv account new folder(s) will be created.

Example request

// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/files/fetch', {
method: 'POST',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' },
body: JSON.stringify([
{
"url": "https://demo.sirv.com/aurora.jpg",
"filename": "/REST API Examples/aurora.jpg"
},
{
"url": "https://demo.sirv.com/missing.jpg",
"filename": "/REST API Examples/missing.jpg"
}
]),
});
console.log(res.status, await res.text());

Example response

[
{
"filename": "/REST API Examples/aurora.jpg",
"success": true,
"attempted": false,
"attempts": [
{
"url": "https://demo.sirv.com/aurora.jpg",
"initiator": {
"type": "api",
"remoteAddr": "176.105.166.4",
"date": "2020-07-17T15:47:35.316Z"
},
"statusCode": 200,
"headers": {
"result": {
"version": "HTTP/1.1",
"code": 200,
"reason": "OK"
},
"Date": "Fri, 17 Jul 2020 15:47:36 GMT",
"Content-Type": "image/webp",
"Content-Length": "201846",
"Connection": "keep-alive",
"Last-Modified": "Fri, 17 Jul 2020 15:47:36 GMT",
"ETag": "\"5f11c818-31476\"",
"Server": "Sirv.Imagination",
"X-Sirv-Server": "c1-extra1-fireball-13",
"X-Sirv-Cache": "MISS",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Expires": "Sun, 16 Aug 2020 15:47:36 GMT",
"Cache-Control": "max-age=2592000",
"X-Sirv-Meta-Width": "2500",
"X-Sirv-Meta-Height": "1667",
"X-Sirv-Shard": "c1-riak1",
"X-Account-Id": "sdulth0oi0t9zxpxqtxwkwvgipjgv6ud",
"X-File-VersionId": "5evxYG8lnBgeA7cGBRTZzq7JQolRYviN:0",
"X-Account-Serial": "2020-06-15T19:18:53.901Z",
"Accept-Ranges": "bytes"
},
"timing": {
"ns": 0.007514,
"connect": 0.007912,
"start": 0.48724,
"total": 0.489622
},
"date": "2020-07-17T15:47:36.712Z"
}
],
"retryAfter": "2020-07-18T15:47:36.712Z"
},
{
"filename": "/REST API Examples/missing.jpg",
"success": false,
"attempted": false,
"attempts": [
{
"url": "https://demo.sirv.com/missing.jpg",
"initiator": {
"type": "api",
"remoteAddr": "176.105.166.4",
"date": "2020-07-18T08:35:51.026Z"
},
"statusCode": 404,
"headers": {
"result": {
"version": "HTTP/1.1",
"code": 404,
"reason": "Not Found"
},
"Date": "Sat, 18 Jul 2020 08:35:52 GMT",
"Content-Type": "text/html; charset=utf-8",
"Content-Length": "4140",
"Connection": "keep-alive",
"Vary": "Accept-Encoding",
"X-Account-Id": "sdulth0oi0t9zxpxqtxwkwvgipjgv6ud",
"X-Account-Serial": "2020-06-15T19:18:53.901Z",
"ETag": "W/\"102c-wKpRt+Cg9Cnw/NpTSkF5+w\"",
"X-Sirv-Cache": "MISS",
"Server": "Sirv.Imagination",
"X-Sirv-Server": "c1-extra1-fireball-15",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*"
},
"timing": {
"ns": 0.018986,
"connect": 0.019303,
"start": 0.103774,
"total": 0.103829
},
"error": {
"name": "Error",
"message": "Request not successful: expected status code 200 but got 404"
},
"date": "2020-07-18T08:35:52.089Z"
}
],
"retryAfter": "2020-07-18T12:07:32.613Z"
}
]
GEThttps://api.sirv.com/v2/files/tus/url

Use this API method to get a link for uploading a file with tus.io.

tus.io uploads send a file in chunks of up to 1 MB, can resume after a broken connection and take files up to 1 GB. The link works for 1 hour unless you set expiresIn, up to 7 days.

Use the link as the endpoint of a tus.io client and give the file’s path in metadata.filename. The file shows in your account 1 to 4 seconds after the upload ends. The steps are in tus.io multipart uploads.

Query parameters

NameTypeRequiredExampleDescription
locationstringYesgb_londonUpload server to send the file to, from List available tus.io locations.
expiresInnumberNo18000URL expiration time in seconds

Example request

// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/files/tus/url?location=gb_london&expiresIn=18000', {
method: 'GET',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },
});
console.log(res.status, await res.text());

Example response

{
"url": "https://sirvcdn-gbr-4.sirv.com:444/upload/eyJhbhoaigGSiuhgkahFFGnX0"
}
GEThttps://api.sirv.com/v2/files/tus/locations

Use this API method to list available tus.io locations.

Each location is an upload server near one city. Pick the one closest to you, then ask for an upload link with Get tus.io upload link. How tus.io uploads work is explained in tus.io multipart uploads.

Example request

// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/files/tus/locations', {
method: 'GET',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },
});
console.log(res.status, await res.text());

Example response

[
"au_sydney",
"br_sao_paulo",
"ca_monreal",
"de_falkenstein",
"fi_helsinki",
"fr_paris",
"gb_london",
"hk_hong_kong",
"in_mumbai",
"kr_seoul",
"nz_christchurch",
"sg_singapore",
"us_atlanta",
"us_buffalo",
"us_chicago",
"us_dallas",
"us_kansas",
"us_los_angeles",
"us_miami",
"us_phoenix",
"us_seattle",
"us_washington",
"za_capetown"
]
POSThttps://api.sirv.com/v2/files/upload

Use this API method to upload a file. If the folder path does not already exist, it will be created. Specify the appropriate content type.

Use binary content encoding (not base64).

Query parameters

NameTypeRequiredExampleDescription
filenamestringYes/REST API Examples/uploaded.txtPath to save the file at, with its name. Missing folders are created.

Example request

import { readFile } from 'node:fs/promises';
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variable
const res = await fetch('https://api.sirv.com/v2/files/upload?filename=%2FREST%20API%20Examples%2Fuploaded.txt', {
method: 'POST',
headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'image/jpeg' },
body: await readFile('image.jpg'),
});
console.log(res.status, await res.text());

Response

HTTP 200 with an empty body when the command succeeds.

Back to top