Skip to content

Upload a file

By , Head of IntegrationsUpdated

Open this page in a new chat

Short answer

Upload a file with POST /v2/files/upload. If the folder path does not already exist, it will be created. Specify the appropriate content type. Use binary content encoding (not base64). Each call needs a bearer token and counts towards your hourly API limit.

After reading this you will know

  • How to upload a file
  • Which parameters it takes
  • Sample code in 9 languages and a sample answer

This command needs a bearer token and counts towards your hourly limit.

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