Skip to main content

Installation

Install the Filejar client:

Basic Setup

Initialize the Filejar client:

Framework Recipes

Filejar works seamlessly with popular Node.js frameworks. Choose your framework to see framework-specific integration examples:

Express

Learn how to integrate Filejar with Express.js using Multer for file uploads.

Hono

Fast and lightweight web framework with built-in file handling.

Fastify

High-performance framework with @fastify/multipart plugin.

NestJS

Enterprise-grade framework with decorators and dependency injection.

ElysiaJS

TypeScript-first framework with built-in type validation.

Uploading Files

Single File Upload

Upload a single file to Filejar:

Multiple Files Upload

Upload multiple files at once:

Working with File Buffers

If you have a file buffer (e.g., from an HTTP request or file system):

Error Handling

Handle errors properly:

File URL Construction

After uploading, construct the file URL using the key:

Complete Example

Here’s a complete example of uploading a file:

TypeScript Support

Filejar includes full TypeScript support:

Best Practices

  1. Always check acknowledgment: Verify that the upload was acknowledged successfully before using the file.
  2. Handle errors gracefully: Use try-catch blocks and check for Filejar.APIError instances.
  3. Store file metadata: Save the key and upload_id in your database for later retrieval.
  4. Use file URLs: Construct file URLs using https://cdn.filejar.dev/${key} for client-side access.
  5. Validate file types: Validate file types and sizes before uploading to avoid unnecessary API calls.