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?

onFileDescriptorFileFailed( )


Triggered when a file fails during post-upload processing.

Method Declaration
Copy
function wixMediaSiteMedia_onFileDescriptorFileFailed(
  event: FileDescriptorFileFailed,
): void;
Method Parameters
eventFileDescriptorFileFailed

Information about the failed file and metadata for the event.

An event that triggers when a file fails during essential post-upload processing
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_onFileDescriptorFileFailed(event) { const eventTime = event.metadata.eventTime; const entityId = event.metadata.entityId; console.log( `File with ID ${entityId} failed during essential post-upload processing at ${eventTime}.`, ); } /* Full event object: * { * "data": { * "externalInfo": {} * }, * "metadata": { * "entityId": "d4dde1_f6660fb1274c41bf87514db2f5926ae0", * "eventTime": "2023-09-18T10:27:33.046Z", * "id": "8cf0189d-9f49-45c5-9f3c-bc7928a42e34", * "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?

onFileDescriptorFileReady( )


Triggered when a file is ready to be used, after any post-upload processing.

This event is also triggered when a file is restored from the Media Manager's trash bin.

Method Declaration
Copy
function wixMediaSiteMedia_onFileDescriptorFileReady(
  event: FileDescriptorFileReady,
): void;
Method Parameters
eventFileDescriptorFileReady

Information about the file and metadata for the event.

An event that triggers when a file is ready to be used
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_onFileDescriptorFileReady(event) { const displayName = event.data.file.displayName; const parentFolderId = event.data.parentFolderId; const eventTime = event.metadata.eventTime; console.log( `${displayName}, located in the parent folder with ID ${parentFolderId}, is ready to be used. Completion of post-upload processing was at ${eventTime}.`, ); } /* Full event object: * { * "data": { * "externalInfo": {}, * "file": { * "_createdDate": "2023-08-09T08:45:49.000Z", * "_id": "d4dde1_e26da94b5cb440649ede0c433425449c~mv2.jpg", * "_updatedDate": "2023-08-09T08:45:49.000Z", * "displayName": "mountains.jpg", * "hash": "800fae3e0cb7908518a391c25864436c", * "labels": [ * "mountainous range", * "mountain range", * "mountain peak", * "mountains", * "snow capped mountains", * "mountainous landscape" * ], * "media": { * "image": { * "colors": { * "palette": [ * { * "rgb": { * "b": 47, * "g": 36, * "r": 31 * } * }, * { * "rgb": { * "b": 155, * "g": 153, * "r": 195 * } * }, * { * "rgb": { * "b": 141, * "g": 123, * "r": 138 * } * }, * { * "rgb": { * "b": 177, * "g": 161, * "r": 190 * } * }, * { * "rgb": { * "b": 179, * "g": 178, * "r": 217 * } * }, * { * "rgb": { * "b": 160, * "g": 176, * "r": 229 * } * }, * { * "rgb": { * "b": 176, * "g": 151, * "r": 162 * } * }, * { * "rgb": { * "b": 93, * "g": 78, * "r": 71 * } * }, * { * "rgb": { * "b": 45, * "g": 63, * "r": 107 * } * }, * { * "rgb": { * "b": 104, * "g": 88, * "r": 82 * } * } * ], * "prominent": { * "rgb": { * "b": 47, * "g": 36, * "r": 31 * } * } * }, * "faces": [], * "image": "wix:image://v1/d4dde1_e26da94b5cb440649ede0c433425449c~mv2.jpg/mountains.jpg#originWidth=5833&originHeight=3894" * } * }, * "mediaType": "IMAGE", * "operationStatus": "READY", * "parentFolderId": "media-root", * "private": false, * "siteId": "c96bcd13-173a-4938-88e0-a126391adf49", * "sizeInBytes": "3013886", * "thumbnailUrl": "https://static.wixstatic.com/media/d4dde1_e26da94b5cb440649ede0c433425449c~mv2.jpg", * "url": "https://static.wixstatic.com/media/d4dde1_e26da94b5cb440649ede0c433425449c~mv2.jpg" * }, * "triggeredByUndelete": true * }, * "metadata": { * "entityId": "d4dde1_e26da94b5cb440649ede0c433425449c~mv2.jpg", * "eventTime": "2023-09-18T10:22:49.159Z", * "id": "6057a4bd-86d1-428e-bfe5-026dcc869ec3", * "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?

onFileDescriptorUpdated( )


Method Declaration
Copy
function wixMediaSiteMedia_onFileDescriptorUpdated(
  event: FileDescriptorUpdated,
): void;
Method Parameters
eventFileDescriptorUpdated

Information about the updated file and metadata for the event.

An event that triggers when a file is updated
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_onFileDescriptorUpdated(event) { const eventTime = event.metadata.eventTime; const displayName = event.entity.displayName; const parentFolder = event.entity.parentFolderId; console.log( `${displayName}, currently located in the parent folder with ID ${parentFolder}, was updated at ${eventTime}.`, ); } /* Full event object: * { * "entity": { * "displayName": "image1", * "mediaType": "IMAGE", * "private": false, * "operationStatus": "READY", * "url": "https://static.wixstatic.com/media/d4dde1_e76448de45bf4deb912b373bc7c3ac6f~mv2.jpg", * "_id": "d4dde1_e76448de45bf4deb912b373bc7c3ac6f~mv2.jpg", * "_createdDate": "2023-08-09T08:45:43.000Z", * "_updatedDate": "2023-09-18T10:22:38.000Z", * "hash": "7fc91042c9a56b42223aa2f94ccdcecd", * "labels": [ * "label1", * "label2" * ], * "sizeInBytes": "6312959", * "media": { * "image": { * "image": "wix:image://v1/d4dde1_e76448de45bf4deb912b373bc7c3ac6f~mv2.jpg/image1#originWidth=5616&originHeight=3744", * "colors": { * "prominent": { * "rgb": { * "r": 39, * "g": 36, * "b": 26 * } * }, * "palette": [ * { * "rgb": { * "r": 39, * "g": 36, * "b": 26 * } * }, * { * "rgb": { * "r": 119, * "g": 125, * "b": 135 * } * }, * { * "rgb": { * "r": 208, * "g": 209, * "b": 208 * } * }, * { * "rgb": { * "r": 130, * "g": 108, * "b": 40 * } * }, * { * "rgb": { * "r": 75, * "g": 101, * "b": 133 * } * }, * { * "rgb": { * "r": 94, * "g": 78, * "b": 36 * } * }, * { * "rgb": { * "r": 148, * "g": 161, * "b": 178 * } * }, * { * "rgb": { * "r": 163, * "g": 177, * "b": 192 * } * }, * { * "rgb": { * "r": 208, * "g": 184, * "b": 159 * } * }, * { * "rgb": { * "r": 183, * "g": 159, * "b": 137 * } * } * ] * }, * "faces": [] * } * }, * "metadata": { * "entityId": "d4dde1_e76448de45bf4deb912b373bc7c3ac6f~mv2.jpg", * "eventTime": "2023-09-18T10:22:39.193Z", * "id": "acfe4b7a-bc6a-41f5-8fb3-d0f1301fea51", * "triggeredByAnonymizeRequest": false * }, * "siteId": "c96bcd13-173a-4938-88e0-a126391adf49", * "thumbnailUrl": "https://static.wixstatic.com/media/d4dde1_e76448de45bf4deb912b373bc7c3ac6f~mv2.jpg", * "parentFolderId": "b2bc72834460412494c93617d88b8c89" * } * } */
Errors

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

Did this help?

onFolderCreated( )


Triggered when a folder is created.

This event is also triggered when a folder is restored from the Media Manager's trash bin.

Method Declaration
Copy
function wixMediaSiteMedia_onFolderCreated(event: FolderCreated): void;
Method Parameters
eventFolderCreated

Information about the created file and metadata for the event.

An event that triggers when a folder is created
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_onFolderCreated(event) { const displayName = event.entity.displayName; const parentFolderId = event.entity.parentFolderId; const eventTime = event.metadata.eventTime; console.log( `New folder, "${displayName}," was created in the parent folder with ID ${parentFolderId} at ${eventTime}.`, ); } /* Full event object: * { * "entity": { * "_createdDate": "2023-09-18T10:20:23.000Z", * "_id": "a7b49f96836a48febefb10f669c14ab0", * "_updatedDate": "2023-09-18T10:20:23.000Z", * "displayName": "Videos", * "parentFolderId": "media-root" * }, * "metadata": { * "entityId": "a7b49f96836a48febefb10f669c14ab0", * "eventTime": "2023-09-18T10:20:24.401Z", * "id": "00c0a4d0-1987-4d2f-9cb4-0dec0b969d60", * "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?