Published
What moves, and what does not
If you store files in S3 and resize images with a Lambda behind a CDN, moving to Fileboy means copying the objects in, then swapping your upload code and image URLs. The bucket, the Lambda and the CDN rules can then be switched off.
Read the S3 and Lambda comparison first. If you need to keep files in your own AWS account for compliance, Fileboy can use your own S3-compatible bucket on the Max plan, which is a different move: it keeps the bucket and replaces the code in front of it.
One file can be up to 5 GB in Fileboy, and an import from a URL has nine minutes in all. Larger objects need splitting or another route. Check your totals against the plan on the pricing page: uploads past the file or storage limit are refused.
1. Map your URLs
Every resizing Lambda defines its own parameters, so this mapping assumes the common width, height, format and quality pattern. Check it against your handler. Fileboy steps go after ?transform= on an /images/get/FILE_ID URL, separated by semicolons.
?width=400becomesresize:400x_. Roughly: it depends on your handler.?width=400&height=300&fit=coverbecomesresize:400x300~fit:cover. Roughly: it depends on your handler.?format=webpbecomesformat:webp, and?quality=80becomesquality:80.
https://cdn.example.com/uploads/boots.jpg?width=400&format=webp
https://api.fileboy.io/images/get/FILE_ID?transform=resize:400x_;format:webp
# A file that is not an image
https://my-bucket.s3.amazonaws.com/uploads/brochure.pdf
https://api.fileboy.io/files/get/FILE_ID2. Copy the bucket
The script lists the bucket, makes a ten-minute presigned link for each object so the bucket can stay private, and asks Fileboy to fetch it with uploadFileFromUrl. Nothing is downloaded to the machine running the script. The S3 key goes in each file's metadata, so a second run skips what is already in, and the folder path in the key becomes a Fileboy folder.
import { S3Client, ListObjectsV2Command, GetObjectCommand } from "@aws-sdk/client-s3"
import { getSignedUrl } from "@aws-sdk/s3-request-presigner"
import { Fileboy } from "@cd2/fileboy-node"
const bucket = "my-bucket"
const s3 = new S3Client({})
const fileboy = Fileboy({
publicKey: process.env.FILEBOY_PUBLIC_KEY,
privateKey: process.env.FILEBOY_PRIVATE_KEY,
})
const failed = []
let token
do {
const page = await s3.send(
new ListObjectsV2Command({ Bucket: bucket, Prefix: "uploads/", ContinuationToken: token }),
)
for (const object of page.Contents ?? []) {
if (object.Key.endsWith("/")) continue // a folder placeholder
try {
const done = await fileboy.listFiles({ metadata: { s3Key: object.Key }, limit: 1 })
if (done.data.length > 0) continue
// A link that works for ten minutes, so the bucket can stay private
const url = await getSignedUrl(s3, new GetObjectCommand({ Bucket: bucket, Key: object.Key }), {
expiresIn: 600,
})
const parts = object.Key.split("/")
const name = parts.pop()
const file = await fileboy.uploadFileFromUrl(url, {
name,
metadata: { s3Key: object.Key },
...(parts.length > 0 && { folderPath: "/" + parts.join("/") }),
})
if (file.fileSize !== object.Size) {
console.warn("Size differs for " + object.Key, file.fileSize, object.Size)
}
} catch (error) {
failed.push(object.Key)
console.error(object.Key, error.message)
}
}
token = page.NextContinuationToken
} while (token)
console.log("Failed: " + failed.length, failed)A sketch to adapt. The Fileboy calls are the library's. The AWS calls are the v3 SDK's, but check its documentation for your version, and try it on one prefix first. Fileboy takes a file's type from what it fetches; if types come out wrong, pass mime in the options.
Fileboy fetches the link from its own servers, so the bucket needs no changes, but the link must be reachable from the public internet. If your bucket is only reachable inside a VPC, download the objects first and upload them from disk with uploadFileFromPath, which takes a resumable option for big files.
3. Write down the new IDs
Your database holds S3 keys or URLs. Add a column for the Fileboy ID, and fill it from this map.
import { writeFile } from "node:fs/promises"
import { Fileboy } from "@cd2/fileboy-node"
const fileboy = Fileboy({
publicKey: process.env.FILEBOY_PUBLIC_KEY,
privateKey: process.env.FILEBOY_PRIVATE_KEY,
})
// Fileboy kept the old id in each file's metadata, so it can write the map for you
const map = {}
let cursor
do {
const page = await fileboy.listFiles({ hasMetadata: ["s3Key"], limit: 100, cursor })
for (const file of page.data) map[file.metadata.s3Key] = file.id
cursor = page.nextCursor ?? undefined
} while (cursor)
await writeFile("s3-map.json", JSON.stringify(map, null, 2))
console.log(Object.keys(map).length + " files in the map")In your app, replace the code that built bucket or CDN URLs with one that builds them from the ID:
// Before: your Lambda's URL
const before = "https://cdn.example.com/" + key + "?width=400&format=webp"
// After
const after = fileboy.buildImageUrl(fileboyId, {
transforms: [
{ type: "resize", width: 400 },
{ type: "format", format: "webp" },
],
})To replace the presigned upload endpoint, use the browser uploader, or upload from your server as the server upload guide shows. Your app then stores a Fileboy ID instead of a key.
4. Check the import
- Count: compare the entries in
s3-map.jsonwith the objects under the prefix, for example withaws s3 ls --recursiveand a line count. Re-run the import: it should report nothing new and an emptyFailedlist. - Sizes: the script warns when a stored size differs from the object's size. Look at every warning.
- Pictures: open a sample of images at the sizes your pages use. Check any with an unusual orientation or colour profile, as your Lambda may have handled them in its own way.
- Other files: download a few PDFs or archives through their new URLs and open them.
5. Cut over
- Set your Fileboy app's allowed origins, and keep the private key on your server only.
- If your bucket was private, turn on signed URLs so Fileboy's files are private too.
- Switch new uploads to Fileboy first. Then run the import once more for what arrived in the meantime.
- Swap the URL builder in your app, on one page first, and compare those pages with the old ones.
- Keep the bucket and the Lambda running for a few weeks. Old links in emails and other sites may still use them. Once your access logs show no more traffic, switch the Lambda and CDN rules off.
- Delete bucket objects last, and only after you have kept a copy of the map. A bucket with versioning or a lifecycle rule is a cheap safety net while you wait.
Checked against the current libraries in November 2026. Found something that no longer works? Tell us.