import Filejar from 'filejar';import { readFile } from 'fs/promises';// Initialize Filejar clientconst filejar = new Filejar({ apiKey: process.env.FILEJAR_API_KEY,});// Read a file from your filesystemconst fileBuffer = await readFile('./example.pdf');const file = new File([fileBuffer], 'example.pdf', { type: 'application/pdf',});// Upload to Filejarconst result = await filejar.upload.uploadFile([file]);// Get the uploaded file detailsconst uploadResult = result.response[0];const acknowledged = result.acknowledge[0];// Your file is now available at:const fileUrl = `https://cdn.filejar.dev/${uploadResult.key}`;console.log('File uploaded successfully!');console.log('File URL:', fileUrl);console.log('File size:', acknowledged.size, 'bytes');
Your uploaded file is immediately available via CDN. Use the URL anywhere:
<!-- In HTML --><img src="https://cdn.filejar.dev/your-file-key" alt="Uploaded image" /><!-- Or in your application --><a href="https://cdn.filejar.dev/your-file-key">Download file</a>