Tokens (Client upload)
Managing large file uploads on the server comes with caveats. The recommended way is to authorize the client to upload a the specific file directly to File0, bypassing your server.
import { f0 } from 'file0';
// Generate a file-scoped token
// With this token you can execute any command scoped to the given file.
const token = await f0.createToken('hello.txt', {
expiresIn: '1h',
maxUploadSize: '1mb',
});
// Use the token to upload the file
// Providing the file name is not required,
// because the token is already containing the file name.
await f0.useToken(token).set(myFile);
// You can also use the token to anything else,
// like to publish or download the file.
await f0.useToken(token).publish();
const text = await f0.useToken(token).get({ as: 'text'});
Last updated