dehaze

File Storage Events

You can trigger webhooks on any file storage operations (create/delete) performed via Space Cloud.

Prerequisiteslink

Make sure you have enabled eventing for your Space Cloud cluster. To enable eventing, head over to the Settings tab in the Eventing section:

Eventing config

Check the Enable eventing module checkbox.

Select an Eventing DB and hit Save.

Eventing DB is used to store event and invocation logs.

Create file storage event triggerlink

Open a project in Mission Control, head to the Event Triggers section and click on the Add button to open the form below:

File storage event trigger

Parameterslink

Trigger Name

Give a unique name for an event trigger. (e.g., upload-profile-pic )

Source

Select File Storage as the event source.

Trigger operation

Select the file storage operation for which you want to create the event trigger. Can be one of:

  • Write: When a file/folder gets written/created.
  • Delete: When a file/folder gets deleted.

Webhook URL

The HTTP(s) URL that should get triggered with the event payload on the configured operation. Must be a POST handler.

Advanced settingslink

Retries

The number of times to retry a failed invocation. Default value is 3.

Timeout

Timeout in milliseconds. Default value is 5000.

Delivery mechanismlink

The webhook is delivered over HTTP POST request to the specified webhook URL with the following headers:

Content-Type: application/json

Event payloadlink

The POST body of the webhook is a JSON object which follows the Cloud Events specs:

{
  "specversion": "1.0-rc1",
  "id": "<unique-uuid>",
  "type": "<event-type>",
  "source": "<space-cloud-node-id>",
  "time": "<date-string>",
  "data": {
    "path": "<file-path>",
    "meta": "Object"
  }
}
Key Type Description
specversion String Version of the Cloud Events specifications.
id String A unique identifier of an event.
type String Event type. One of FILE_CREATE or FILE_DELETE .
source String Unique identifier of a Space Cloud instance.
time String Time at which the event occurred(ISO 8601 format).
data.path String Path of the concerned file/folder.
data.meta String meta object sent by the client while creating/deleting file.

For example:

{
  "specversion" : "1.0-rc1",
  "id": "43e32d79-f2bf-41c0-be5f-a75c8c1bcfbf",
  "type": "DB_INSERT",
  "source": "1fb07d5d-b670-468e-ba94-ad5f06a5c053",
  "time": "2019-10-19T12:40:50.053Z",
  "data": {
    "path": "/users/1/profile.jpg",
    "meta": {
      "file_size": 100,
      "upload_date": "2019-10-19T12:40:50.053Z"
    }
  }
}

Note: The meta object is not generated by Space Cloud. It is an optional field sent by the client as a stringified JSON in the formdata at meta key while creating/deleting a file/folder.

Webhook response structurelink

A 2xx response status code from the webhook target is deemed to be a successful invocation of the webhook. Any other response status results in an unsuccessful invocation that causes retries as per the retry configuration.

Have a technical question?

Improve the docs!