homeaboutvideotry it nowpricingdocs
Guide

Upload files from Node.js: disk, buffers, streams and URLs

Move files from a script or server into hosted storage, without writing any storage code. Examples for Node.js, Ruby, Python, PHP and cURL.

When you upload from the server

This guide uses Node.js, and the steps have the Ruby, Python, PHP and cURL version in a tab. Browser uploads cover user files. Server-side uploads cover everything else: importing an existing archive, saving a PDF your code generated, copying images from a third-party feed, or a nightly job that mirrors files. The same hosted storage and the same IDs apply, so a file you upload here is shown in your app like any other.

Set up the client

Install
npm install @cd2/fileboy-node

On the server, give the client your private key as well as your public key. Requests it makes are signed with that key. Keep the private key in an environment variable and never ship it to a browser.

import { Fileboy } from "@cd2/fileboy-node"

const fileboy = Fileboy({
  publicKey: process.env.FILEBOY_PUBLIC_KEY!,
  privateKey: process.env.FILEBOY_PRIVATE_KEY!,
})

From a path on disk

const file = await fileboy.uploadFileFromPath("./exports/report.pdf", {
  metadata: { customerId: "cus_123", kind: "monthly-report" },
})

console.log(file.id) // save this

From a buffer or a stream

When the data is not on disk, pass it directly. Name the file, because data in memory has no name of its own.

// a Buffer you generated
const invoice = await fileboy.uploadFile(pdfBuffer, {
  name: "invoice-1042.pdf",
  mime: "application/pdf",
})

From a remote URL

Fileboy fetches the file itself, so it never passes through your machine. Use expect to refuse anything that is not the type you meant to import.

const photo = await fileboy.uploadFileFromUrl("https://example.com/photo.jpg", {
  name: "photo.jpg",
  expect: "image/jpeg",
})

Only public, internet-reachable addresses can be fetched this way. URLs that point at internal or private network addresses are refused.

Read a file's details and build URLs

// the details of one file: name, mime, size, hash, metadata
const data = await fileboy.fetchFileData(file.id)

// a URL for a file or an image
const link = fileboy.buildFileUrl(file.id, { download: true })
const thumb = fileboy.buildImageUrl(photo.id, {
  transforms: [{ type: "resize", width: 300 }],
})

Save the returned id in your own database next to the record it belongs to. Metadata is stored with the file and returned in its details, but treat it as a note, not as your source of truth. See the Node library docs for the rest of the client.

Checked against the current libraries in November 2026. Found something that no longer works? Tell us.

Go deeper

Still choosing a tool?

Fileboy is small on purpose. This comparison says where it fits and where another option is the better call.

Fileboy vs S3 + Lambda · All comparisons

Try it

The free plan needs no card and includes 1,000 files, so you can run every example above.

More guides: How to add image upload to a React app · Resize images on the fly with a URL · Stream video with HLS without running ffmpeg · Add captions and subtitles to a video · All guides

Add Fileboy to your next project

We built Fileboy to stop rebuilding file handling for every app. Create an app, paste your key and upload a file. The free plan needs no card.