Build features
Files
Store receipts, photos and PDFs your app's users upload.
Each app has its own private file storage. Files are never public: your server code asks Inhaus for a short-lived link each time it reads or writes one.
Save a file
import { files, getUser } from '@inhaus/sdk';
export default {
async fetch(request: Request, env: Env) {
const url = new URL(request.url);
if (url.pathname === '/api/receipts' && request.method === 'POST') {
const user = getUser(request);
const form = await request.formData();
const file = form.get('receipt') as File;
const key = `receipts/${user.id}/${crypto.randomUUID()}-${file.name}`;
await files.put(env, key, await file.arrayBuffer(), file.type);
return Response.json({ key });
}
return new Response('Not found', { status: 404 });
},
};Read a file
// Stream it through your app
const res = await files.get(env, key);
if (!res) return new Response('Not found', { status: 404 });
return new Response(res.body, { headers: { 'content-type': res.headers.get('content-type') ?? 'application/octet-stream' } });// Or hand the browser a link that works for 5 minutes
const link = await files.url(env, key);
return Response.redirect(link, 302);Delete a file
await files.delete(env, key);Limits
- Up to 25 MB per file.
- Files belong to the app, not the workspace. They move with the app and are deleted 7 days after the app is deleted.
See the full files reference.