Files
Upload files with progress, build file and thumbnail URLs, and read protected files with the Dart SDK.
Upload
Section titled “Upload”final metas = await vb.files.upload('posts', post.id, 'gallery', [ UploadFile.fromBytes('a.png', bytes, contentType: 'image/png'), UploadFile.fromStream('video.mp4', () => file.openRead(), length: await file.length()),], onProgress: (sent, total) => print('$sent / $total'));
// Attach what was uploaded to the recordawait vb.collection('posts').update(post.id, { 'gallery': [for (final m in metas) m.filename],});upload always returns a list of FileMeta (filename, originalName,
size, mimeType). fromStream takes a function that opens the stream, so
the upload can be sent again after a token refresh.
vb.files.url(filename);vb.files.url(filename, thumb: '400x0'); // width 400, keep ratiovb.files.url(filename, thumb: '200x200', fit: ThumbFit.cover);vb.files.url(filename, format: ImageFormat.webp, quality: 80);Use the Uri with Image.network(url.toString()).
Protected files
Section titled “Protected files”A protected file needs a short-lived token:
final url = await vb.files.urlWithToken('docs', doc.id, 'secret', filename);Tokens are cached until shortly before they expire (one-time tokens never
are), and the cache is dropped when a different user signs in.
vb.files.token(...) returns the token itself.
Delete
Section titled “Delete”await vb.files.delete('posts', post.id, 'gallery', filename); // one fileawait vb.files.delete('posts', post.id, 'gallery'); // the whole fieldSince server 0.27.3 a delete also takes the name out of the record’s field.