File Storage
For storing large files outside the database, configure the fileStore interface. This is useful for handling file uploads, temporary files, and other binary data that shouldn’t be stored in the database.
Configuration
Section titled “Configuration”The fileStore interface requires three methods:
storeFile(content)- Store a file and return a unique referencegetFile(fileRef)- Retrieve a file by its referencedeleteFile(fileRef)- Delete a file by its reference
Platform Examples
Section titled “Platform Examples”Generic Implementation
Section titled “Generic Implementation”configuration.fileStore = { async storeFile(content) { // Store file and return reference return fileReference; }, async getFile(fileRef) { // Retrieve file by reference return fileBuffer; }, async deleteFile(fileRef) { // Delete file by reference }};AWS S3
Section titled “AWS S3”const AWS = require('aws-sdk');const s3 = new AWS.S3();
configuration.fileStore = { async storeFile(content) { const fileId = `file_${Date.now()}_${Math.random()}`; await s3.putObject({ Bucket: 'my-bucket', Key: fileId, Body: content }).promise(); return fileId; }, async getFile(fileId) { const result = await s3.getObject({ Bucket: 'my-bucket', Key: fileId }).promise(); return result.Body; }, async deleteFile(fileId) { await s3.deleteObject({ Bucket: 'my-bucket', Key: fileId }).promise(); }};S3 Setup:
- Install AWS SDK:
Terminal window npm i aws-sdkTerminal window pnpm add aws-sdkTerminal window yarn add aws-sdk - Configure AWS credentials (environment variables, IAM role, or credentials file)
- Create an S3 bucket in your AWS account
- Grant appropriate permissions to your application
Cloudflare KV
Section titled “Cloudflare KV”import type { FileStore } from '@crowdin/app-project-module/out/types';
const configuration: ClientConfig = { // ... other config fileStore: { getFile: async (fileId: string): Promise<Buffer> => { const data = await env.KVStore.get(fileId, 'arrayBuffer'); if (!data) { throw new Error(`File not found: ${fileId}`); } return Buffer.from(data); }, storeFile: async (content: Buffer): Promise<string> => { const fileId = `file_${crypto.randomUUID()}`; // Files expire after 24 hours (86400 seconds) await env.KVStore.put(fileId, content, { expirationTtl: 86400 }); return fileId; }, deleteFile: async (fileId: string): Promise<void> => { await env.KVStore.delete(fileId); } }};KV Setup:
- Create namespace:
npx wrangler kv namespace create KVStore - Add to
wrangler.jsonc:"kv_namespaces": [{"binding": "KVStore","id": "your-kv-namespace-id"}]
See the Cloudflare Workers deployment guide for a complete example.