homeaboutvideotry it nowpricingdocs
Docs

Getting Started

Node integration

We offer a powerful and customizable javascript library which allows you to integrate Fileboy into your applications in minutes.

Setting up Fileboy

The

@cd2/fileboy-node
library provides utilities for creating quick and understandable file based workflows. Including the ability to upload, retrieve, update and delete files.

Setting up the node library is simple and should only take about 15 minutes to get up and running. The first step is to create a Fileboy account. Once created you need to obtain your API keys by either creating a new application or retrieving them for an existing app.

Installation

Firstly, you need to include the

@cd2/fileboy-node
library into your project, this can be done by running
npm install @cd2/fileboy-node --save
in your project, or
yarn add @cd2/fileboy-node
for yarn users.

1
2
3
4
5
npm install @cd2/fileboy-node --save

or

yarn add @cd2/fileboy-node

Creating a client

After installing the library you can now create an instance of the Fileboy client, this will give you the ability to control your application such as uploading files. To create the client you will need to supply your API keys.

1
2
3
4
5
6
import { Fileboy } from "@cd2/fileboy-node"

const fileboy = Fileboy({
  publicKey: "YOUR PUBLIC KEY",
  privateKey: "YOUR PRIVATE KEY",
})

Using the client

Now you have a client created you can use it to interact with your application. To upload a file you can simply call

fileboy.uploadFile
passing it the file you want to upload, which can be a File object, a Buffer or a Stream. Additionlly, you can specify options such as metaData.

The example shows using the fs package to read a file, then uploading it.

1
2
3
4
5
const myFile = fs.readFile("./bobs_face.png")

const file = await fileboy.uploadFile(
  myFile
)

Retrieving a file is just as simple by using the

saveFile
method. This function takes a file id and a path to store the file. The client will then download the file and store it in the specified path.

Options can be passed as an optional third argument to apply transformations to the file. Read more about them here.

1
await fileboy.downloadFile(file.id, "./downloadedFile.png")

The node client has many other functions to help you write clean and understandable code, all of which are documented below.

Available Methods

fileboy.buildFileUrl(id, options)

Construct a URL to retrieve a given file. You can also provide a single argument of an options object containing an additional property of id or label.

Arguments

id string

The id or label of the file

options (optional) object

options.filename (optional) string

The name of the file to use when using this url to download the file

options.download (optional) boolean

If true then navigating to the produced url will download the file instead of attempting to render it

Returns

string

A URL for the file

fileboy.buildImageUrl(id, options)

Construct a URL to retrieve a given image, optionally supplying a transform to perform. You can also provide a single argument of an options object containing an additional property of id or label.

Arguments

id string

The id or label of the image

options (optional) object

options.filename (optional) string

The name of the file to use when using this url to download the file

options.download (optional) boolean

If true then navigating to the produced url will download the file instead of attempting to render it

transformations (optional) array of transform objects

Transformations to apply to the image. For a list of transformation options see the transformation section of the docs.

Returns

string

A URL for the image

fileboy.downloadFile(id, options)

Given a file id, download the file at return a Buffer containing the file data

Arguments

id string

The id of the file to download

options (optional) object

options.range (optional) [number, number?]

If given, a range header will be added to the request allowing you to request just a part of the file

Returns

Promise<Buffer>

The file data

fileboy.downloadImage(id, options)

Given an image id, download the image at return a Buffer containing the file data

Arguments

id string

The id of the image to download

options (optional) object

Options for transforming the image, as described in buildImageUrl.

options.filename (optional) string

The name of the file to use when using this url to download the file

Returns

Promise<Buffer>

The image data

fileboy.downloadFileToPath(id, filePath, options)

Given a file id, download the file and store it at the given path

Arguments

id string

The id of the file to download

filePath string

The path at which to save the file

options (optional) object

options.range (optional) [number, number?]

If given, a range header will be added to the request allowing you to request just a part of the file

Returns

Promise<void>

fileboy.downloadImageToPath(id, filePath, options)

Given an image id, download the file and store it at the given path

Arguments

id string

The id of the image to download

filePath string

The path at which to save the file

options (optional) object

Options for transforming the image, as described in buildImageUrl.

options.filename (optional) string

The name of the file to use when using this url to download the file

Returns

Promise<void>

fileboy.fetchFileData(id)

Retrieve all of the data for a given file id

Arguments

id string

The id of the image to download

Returns

Promise<FileData>

The file data. Read more about it here

fileboy.hashFile(file)

Retrieve all of the data for a given file id

Arguments

file File | Buffer | Stream | Blob

The file object to generate a hash from

Returns

Promise<string>

The hash of the file object. Read more about the hash here

fileboy.compareFileHash(fileId, file)

This function will return true if the id of the file has the same hash as the given data. This function can be useful when wanting to check if a file has been updated without needing to spend time upload a file.

Arguments

fileId string

file File | Buffer | Stream | Blob

The file object to generate a hash from

Returns

Promise<boolean>

Whether the given file matches that of the one stored against the given fileId.

fileboy.listFileData(filter)

Finds your files by hash or metadata, following every page. Needs the private key. For paging, sorting and the other filters use listFiles.

Arguments

filter object

an object specifying how to reduce the number of returned results. Must contain either filter.hash or filter.metadata

filter.hash (optional) string

only return files with a matching hash.

filter.metadata (optional) metadata

an object containing string keys and values. Any file which has meta data containing all of the given keys will be returned. For instance searching for
{ usage: "logo" }
could return anything such as
{ usage: "logo", region: "footer" }
or
{ usage: "logo", name: "header-image" }
but not
{ usage: "something else" }
.

Returns

Promise<FileData[]>

The a list of all file data which matches the query.

fileboy.uploadFile(file, options)

Upload a file.

Arguments

file File | Buffer | Stream | Blob

The file object to generate a hash from

options (optional) object

additional options to alter the upload

options.name (optional) string

the name of the file being uploaded

options.mime (optional) string

specify a customer mime

options.metadata (optional) metadata

metadata to add to the file

Returns

Promise<FileData>

The file data of the uploaded file.

fileboy.uploadFileFromPath(filePath, options)

Upload a file from the filesystem.

Arguments

filePath string

A path to a file to upload

options (optional) object

additional options to alter the upload

options.name (optional) string

the name of the file being uploaded

options.mime (optional) string

specify a customer mime

options.metadata (optional) metadata

metadata to add to the file

Returns

Promise<FileData>

The file data of the uploaded file.

fileboy.uploadFileFromUrl(url, options)

Upload a file from a url.

Arguments

url string

A URL leading to a file

options (optional) object

additional options to alter the upload

options.name (optional) string

the name of the file being uploaded

options.mime (optional) string

specify a customer mime

options.metadata (optional) metadata

metadata to add to the file

options.expect (optional) string or string[]

Expected mime type to be returned from the URL. The upload will fail if the response does not match it.

Returns

Promise<FileData>

The file data of the uploaded file.

fileboy.listFiles(options)

Lists your files one page at a time, newest first. Needs the private key. Images Fileboy generates when resizing are not listed.

Arguments

options (optional) object

limit (1 to 100), cursor, sort (createdAt, name or fileSize), order (asc or desc), label, mime (a type prefix such as image/), name (contains), hash, metadata (exact key and value pairs), createdBefore and createdAfter (Date or ISO string).

Returns

Promise<{ data: ManagedFile[], nextCursor: string | null }>

One page of files, each with labels. Pass nextCursor as cursor for the next page.

fileboy.updateFileData(fileId, data)

Updates a file. Only the fields you pass change. Needs the private key.

Arguments

fileId string

The id of an uploaded file

data object

Data to update the file with.

data.name (optional) string

A new name for the file.

data.metadata (optional) metadata

Pairs to set, merged into the existing metadata. A null value removes a key.

data.replaceMetadata (optional) boolean

Replace all the metadata with data.metadata instead of merging.

data.mime (optional) string

A new type for the file.

data.labels (optional) { add?: string[], remove?: string[] }

Labels to point at the file or take off it.

data.sharePage (optional) boolean

Turn the file's share page on or off. buildSharePageUrl(id) gives its link, and signSharePageUrl(id, { expiresIn }) a signed link for a file that needs a signed URL.

Returns

Promise<FileData>

The updated file, with labels.

fileboy.destroyFile(fileId)

Permanently deletes a file, its stored data and cached resized copies, and sends a file.deleted webhook. Throws a notFound error if there is no such file. Needs the private key.

Arguments

fileId string

The id of an uploaded file

Returns

Promise<void>

fileboy.destroyFiles(ids)

Deletes up to 100 files at once. Unknown ids are reported in notFound instead of throwing, so it is safe to repeat. Needs the private key.

Arguments

ids string[]

File ids.

Returns

Promise<{ deleted: string[], notFound: string[], failed: { id, message }[] }>

Files in failed are still there because storage could not be reached: send them again.

fileboy.listVideos(options)

Lists your videos one page at a time. Options: limit, cursor, sort (createdAt or name), order, name, status (pending, processing, ready or failed), tags (videos with every one of them), metadata (pairs that must all match), createdBefore and createdAfter. Each video has its description, tags and metadata.

Arguments

options (optional) object

Filters and paging.

Returns

Promise<{ data: ManagedVideo[], nextCursor: string | null }>

fileboy.updateVideo(videoId, { name, description, tags, metadata, replaceMetadata })

Changes a video's name, description, tags or metadata. Only what you pass changes. The description shows on the watch page, tags and metadata are private.

Arguments

videoId string

The video's id.

data.name (optional) string

The new name.

data.description (optional) string | null

Plain text up to 5000 characters. "" or null removes it.

data.tags (optional) string[] | null | { add?, remove? }

A list replaces the tags, null removes them all, { add, remove } changes some. Up to 50 of up to 64 characters, no commas.

data.metadata (optional) Record<string, string | null>

Merged into the existing metadata, null removes a key. replaceMetadata: true replaces it all.

Returns

Promise<ManagedVideo>

fileboy.destroyVideo(videoId)

Deletes a video with its original, renditions, posters and transcripts, and sends video.deleted.

Arguments

videoId string

The video's id.

Returns

Promise<void>

fileboy.listLabels() / createLabel(name, { fileId }) / destroyLabel(name)

List, create and delete labels. Deleting a label keeps the file it points at.

Arguments

name string

The label.

Returns

Promise<ILabel>

fileboy.getUsage()

How many files and videos the app has, the bytes it stores and the plan's limits.

Arguments

Returns

Promise<IUsage>

fileboy.getStorageUsage({ days, top })

What the app stores by kind (images, other files, video originals, renditions, posters, captions, cached image copies), its biggest files and videos, and one total a day. storageBytes matches getUsage().

Arguments

days (optional) number

How many days of daily totals, 1 to 365. Defaults to 30.

top (optional) number

How many of the biggest files and videos to list, 1 to 50. Defaults to 10.

Returns

Promise<IStorageUsage>

verifyWebhook(rawBody, headers, secret, options)

Checks that a webhook came from Fileboy and is recent, then returns the typed event. It is exported from the package rather than the client, so it does not need your keys. Throws a WebhookVerificationError if the signature does not match or the timestamp is outside the allowed window.

Arguments

rawBody string | Buffer

The request body exactly as received, not parsed JSON

headers object | Headers

The request headers, for example req.headers in Express

secret string

The endpoint's signing secret from the dashboard

options.toleranceSeconds (optional) number

How far the timestamp may be from now, in seconds. Defaults to 300.

Returns

IWebhookEvent

fileboy.createAccessToken(options)

Creates a signed access token that can be used to grant specific permissions.

Arguments

options object

Options describing the permissions granted by the token.

options.read (optional) boolean | string[]

The files (ids or labels) that this token grants read access to. Providing true is interpreted as 'all files' and providing false is interpreted as 'no files'. Defaults to false.

options.write (optional) boolean | string[]

The files (ids or labels) that this token grants write access to. Providing true is interpreted as 'all files' and providing false is interpreted as 'no files'. Write access includes both updating and deleting. Defaults to false.

options.upload (optional) boolean

Whether or not this token grants permission to upload new files. Defaults to false.

options.expiresInSeconds (optional) number

The number of seconds until the token expires. Defaults to 60.

Returns

string
hello@fileboy.io

Fileboy

HomeAboutPricingChangelog
© Copyright 2026, CD2 Solutions Ltd.
Terms and ConditionsPrivacy Policy