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:
Event handler functions are defined using the following pattern:
For example, an event handler that handles the update of a file descriptor looks like:
Triggered when a file is deleted.
Contains metadata for the event.
This method doesn't return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Triggered when a file fails during post-upload processing.
function wixMediaSiteMedia_onFileDescriptorFileFailed(
event: FileDescriptorFileFailed,
): void;
Information about the failed file and metadata for the event.
// 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
* }
* }
*/
This method doesn't return any custom errors, but may return standard errors. Learn more about standard Wix errors.