Ir al contenido
v2.7

Enlaces para compartir

Dar acceso a un archivo a quien no tiene cuenta, con vigencia.

Un enlace para compartir abre un archivo a quien no tiene cuenta en el proyecto, sin tocar sus permisos. Por detrás, es un token del archivo, con vigencia opcional, que va en la URL.

En el bucket, abre el archivo y usa Enlaces para compartir → Crear enlace. Se puede cambiar la vigencia y revocar después.

link-compartilhado.ts
import { Tokens } from '@owbase/node';
import { client } from './client';
// The key needs the tokens.write scope.
const tokens = new Tokens(client);
const file = { bucketId: 'invoices', fileId: '<FILE_ID>' };
// A link valid for 7 days, for people who have no account in the project.
const expires = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString();
const token = await tokens.createFileToken({ ...file, expire: expires });
// The same address that storage.getFileView({ ..., token }) from @owbase/web builds.
const link = new URL(`https://cloud.owbase.dev/v1/storage/buckets/${file.bucketId}/files/${file.fileId}/view`);
link.searchParams.set('project', '<PROJECT_ID>');
link.searchParams.set('token', token.secret);
console.log(link.toString());
  • Sin expire, el enlace no vence; revócalo con tokens.delete({ tokenId }) cuando ya no sirva.
  • tokens.list({ bucketId, fileId }) muestra los enlaces de un archivo.
  • En el navegador, @owbase/web arma la misma URL con storage.getFileView({ bucketId, fileId, token }).
¿Te ayudó esta página?