Introduction

Wix Media events are triggered on your site's backend when certain events occur in your media manager. You can write event handlers that react to these events. Event handler functions receive data that corresponds to the event that was fired. Use event handlers to create custom responses to media events.

To add a Wix Media event handler, add an events.js file to the Backend section of your site if one does not already exists. All event handler functions for your site are defined in this file.

Notes:

  • This module is universal. Functions in this module can run on both the backend and frontend, unless specified otherwise.
  • Backend events don't work when previewing your site.

Event handler functions are defined using the following pattern:

Copy

For example, an event handler that handles the update of a file descriptor looks like:

Copy
Did this help?

onFileDescriptorDeleted( )


Triggered when a file is deleted.

Method Declaration
Copy
function wixMediaSiteMedia_onFileDescriptorDeleted(
  event: FileDescriptorDeleted,
): void;
Method Parameters
eventFileDescriptorDeleted

Contains metadata for the event.

An event that triggers when a file is deleted
JavaScript
// Place this code in the events.js file // of your site's Backend section. // Add the file if it doesn't exist. export function wixMediaSiteMedia_onFileDescriptorDeleted(event) { const eventTime = event.metadata.eventTime; const entityId = event.metadata.entityId; console.log(`File with ID ${entityId} was deleted at ${eventTime}.`); } /* Full event object: * { * "metadata": { * "entityId": "d4dde1_e26da94b5cb440649ede0c433425449c~mv2.jpg", * "eventTime": "2023-09-18T10:22:56.532Z", * "id": "c5ad126c-26f0-4ccf-a53c-fa43ea1428bf", * "triggeredByAnonymizeRequest": false * } * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?