Dart - bucket.on()
Create a new bucket notification trigger when certain files are created or deleted.
import 'package:nitric_sdk/nitric.dart';import 'package:nitric_sdk/resources.dart';// Create a readable, writable, and deletable reference to an 'assets' bucketfinal assets = Nitric.bucket("assets").allow([BucketPermission.read,]);// The request will contain the name of the file `key` and the type of event `type`assets.on(BlobEventType.delete, '*', (ctx) async {print("A file named ${ctx.req.file.key} was deleted");return ctx;});assets.on(BlobEventType.write, '/images/cat', (ctx) async {print("A cat image was created");return ctx;});assets.on(BlobEventType.write, '/images/dog', (ctx) async {final dogImage = await ctx.req.file.read();print(dogImage)return ctx;});
Parameters
- Name
blobEventType
- Required
- Required
- Type
- BlobEventType.write or BlobEventType.delete
- Description
The notification type for a triggered event, either on a file write or a file delete.
- Name
keyPrefixFilter
- Required
- Required
- Type
- String
- Description
The file prefix filter that must match for a triggered event. If multiple filters overlap across notifications, an error will be thrown when registering the resource.
- Name
middleware
- Required
- Required
- Type
- BlobEventHandler
- Description
The middleware (code) to be triggered by the bucket notification being triggered.
Available trigger types:
BlobEventType.write
Run when a file in the bucket is created using: file.write()
BlobEventType.delete
Run when a file in the bucket is deleted using: file.delete()
Trigger type cloud mapping
Permission | AWS | GCP | Azure |
---|---|---|---|
BlobEventType.write | s3:ObjectCreated:* | OBJECT_FINALIZE | Microsoft.Storage.BlobCreated |
BlobEventType.delete | s3:ObjectRemoved:* | OBJECT_DELETE | Microsoft.Storage.BlobDeleted |
Last updated on Nov 8, 2024