Dart SDK - Storage#

S3-compatible object storage: buckets, objects, folders and presigned URLs.

Buckets#

final bucket = await db.storage.createBucket(
  name: 'Avatars',
  slug: 'avatars',
  isPublic: true,
  fileSizeLimit: 5 * 1024 * 1024,                 // optional, bytes
  allowedMimeTypes: ['image/png', 'image/jpeg'],  // optional
);
// bucket.data!['id']

await db.storage.listBuckets();
await db.storage.getBucket(bucketId);
await db.storage.deleteBucket(bucketId);
DART

Objects#

await db.storage.listObjects(bucketId);
await db.storage.createFolder(bucketId, 'user-uploads');
await db.storage.deleteObject(objectId);
DART

Upload#

Get a presigned URL, then PUT the bytes to it:

import 'package:http/http.dart' as http;

final upload = await db.storage.signedUploadUrl(
  bucketId: bucketId,
  objectName: 'user-1.png',
  contentLength: 20480, // optional
);

await http.put(
  Uri.parse(upload.data!['url'] as String),
  body: bytes,
);
DART

Download#

final download = await db.storage.signedDownloadUrl(objectId);

// Public URL (no auth, public buckets only)
final public = db.storage.publicUrl(bucketId, objectId);
DART

Next: Environment variables.