@geekapps/silo-fastify
v0.1.0
Published
Fastify plugin to embed Silo file handling in any Fastify app
Downloads
314
Readme
@geekapps/silo-fastify
Fastify plugin that lets any Fastify app expose presigned-upload routes backed by the central Silo API — no local disk storage. The plugin authenticates to Silo with a service account (OAuth2 client-credentials) and proxies the multipart-upload flow: callers ask for an upload URL, PUT the file bytes directly to storage, then hit the complete route to finalize.
This package is a server plugin, not a client SDK. For browser/Next.js uploads use @geekapps/silo-nextjs instead.
Install
import Fastify from "fastify";
import siloPlugin from "@geekapps/silo-fastify";
const app = Fastify();
await app.register(siloPlugin, {
apiUrl: "https://api.silo.geekapps.com.br",
serviceAccount: {
issuerUrl: "https://api.silo.geekapps.com.br",
clientId: process.env.SILO_CLIENT_ID!,
clientSecret: process.env.SILO_CLIENT_SECRET!,
},
});Options (SiloPluginOptions)
| Option | Required | Default | Description |
| ---------------- | -------- | ----------- | ----------------------------------------------------- |
| apiUrl | yes | — | Base URL of the central Silo API |
| serviceAccount | yes | — | { issuerUrl, clientId, clientSecret } for OAuth2 client-credentials auth |
| defaultBucket | no | "default" | Bucket used when the caller doesn't specify one |
| prefix | no | /silo | Route prefix |
Upload flow
POST {prefix}/upload/start— body:{ fileName, mimeType, size, bucket?, isPrivate?, expiresIn?, image?, video? }. Starts a multipart upload on the central Silo API and returns a presigned URL for part 1:{ "fileId": "...", "uploadId": "...", "uploadUrl": "https://..." }The caller
PUTs the file bytes touploadUrldirectly (bypassing this server) and keeps the returnedETag.For files split into more than one part,
GET {prefix}/upload/:fileId/part?uploadId=&partNumber=returns a presigned URL for any additional part.POST {prefix}/upload/:fileId/complete— the caller reports completion here once all parts are uploaded. Body:{ uploadId, parts: [{ PartNumber, ETag }], image?, video? }. This finalizes the file on Silo and returns the resulting file record.DELETE {prefix}/upload/:fileId— body:{ uploadId }. Aborts an in-progress upload.
Downloads
POST {prefix}/files/:fileId/sign — body: { ttl?, disposition? }. Proxies to the central Silo API's sign endpoint and returns a presigned download URL.
Decorator
fastify.silo.request(path, init?) is available on the Fastify instance to call any other central Silo API route directly, using the same service-account auth as the routes above.
⚠️ No caller authentication
None of the routes authenticate who is calling — they only authenticate this server to the central Silo API via the service account. Anyone who can reach these routes can start/complete uploads and mint signed download URLs. Put your own auth (API gateway, internal network boundary, or a Fastify onRequest hook) in front of this plugin if callers need to be authenticated or scoped.
