.NET - Bucket.On()

Create a new bucket notification trigger when certain files are created or deleted.

using System;
using Nitric.Sdk;
using Nitric.Sdk.Resource;
using Nitric.Sdk.Storage;
using BucketNotificationType = Nitric.Sdk.Function.BucketNotificationType;

var assets = Nitric.Bucket("assets");

var accessibleAssets = Nitric.Bucket("assets").With(BucketPermission.Reading);

// The request will contain the name of the file `Key` and the type of event `NotificationType`
assets.On(BucketNotificationType.Delete, "*", context => {
  Console.WriteLine("A file named " + context.Req.Key + "was deleted");

  return context;
});

assets.On(BucketNotificationType.Write, "/images/cat", context => {
  Console.WriteLine("A cat image was written");

  return context;
});

// If `.On()` is called with a permissioned bucket, a file reference will also be provided with the request
accessibleAssets.On(BucketNotificationType.Write, "/images/dog", context => {
  var dogImage = context.Req.File.Read();

  Console.WriteLine(dogImage.ToString());

  return context;
});

Nitric.Run();

Parameters

  • Name
    name
    Required
    Required
    Type
    string
    Description

    The unique name/reference to the file.

  • Name
    notificationType
    Required
    Required
    Type
    BucketNotificationType.Write | BucketNotificationType.Delete
    Description

    The notification type for a triggered event, either on a file write or a file delete.

  • Name
    notificationPrefixFilter
    Required
    Required
    Type
    string
    Description

    The file prefix filter that must match for a triggered event. If multiple filters overlap across notifications then an error will be thrown when registering the resource.

  • Name
    middleware
    Required
    Required
    Type
    BucketNotificationMiddleware | BucketNotificationMiddleware[]
    Description

    The middleware (code) to be triggered when a bucket event is triggered.

Available Trigger Types

BucketNotificationType.Write

Triggered when a file in the bucket is created using: file.Write()

BucketNotificationType.Delete

Triggered when a file in the bucket is deleted using: file.Delete()

Cloud Trigger Types

PermissionAWSGCPAzure
BucketNotificationType.Writes3:ObjectCreated:*OBJECT_FINALIZEMicrosoft.Storage.BlobCreated
BucketNotificationType.Deletes3:ObjectRemoved:*OBJECT_DELETEMicrosoft.Storage.BlobDeleted