CorvidReference

Events

Events fired by the Wix Media API.

Wix Media events are fired when certain events occur with files created using the Media API. You can write event handlers that react to these events. Event handler functions receive data that corresponds to the event that has occurred. Use event handlers to create custom responses to media events.

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

Event handler functions are defined using the following pattern:

 export function <wixAppName>_<eventName>(event) { }

For example, an event handler that handles a file being uploaded to the Media Manager looks like this:

 export function wixMedia_onFileUploaded(event) { }

Note that backend events don't work when previewing your site.

Table of Contents

FUNCTIONS

?
Perform actions on an object.
onFileUploaded( )An event that fires when a file has completed uploading.
onVideoTranscoded( )An event that fires when a video file has completed transcoding.

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
FileEventAn object representing an uploaded file and upload context.

onFileUploaded( )

An event that fires when a file has completed uploading.

Description

The onFileUploaded() event handler runs when a file has been uploaded to to the Media Manager using the importFile(), upload() function, or the URL and token returned by the getUploadUrl() function.

The received FileEvent object contains information about the uploaded file and the upload context.

Note

Backend events don't work when previewing your site.

Syntax

function onFileUploaded(event: FileEvent): void
PARAMETERS
?
Values that you pass to a function.
event
The uploaded file information.

Examples

Receive an event when a file has been uploaded

// Place this code in the events.js file
// of your site's Backend section.

export function wixMedia_onFileUploaded(event) {
  let fileName = event.fileInfo.fileName;
}

/*  Full event object:
 *  {
 *    "fileInfo": {
 *      "mediaType": "image",
 *      "height": 300,
 *      "sourceUrl": "https://somedomain.com/img/original-name.jpg",
 *      “fileName": "f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *      "mimeType": "image/jpeg",
 *      "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
 *      "opStatus": "READY",
 *      "labels": [
 *        "Blue",
 *        "Butterfly",
 *        "Turquoise"
 *      ],
 *     "fileUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
 *     "originalFileName": "original-name.jpg",
 *     "sizeInBytes": 51085,
 *     "isPrivate": false,
 *     "width": 300,
 *     "iconUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
 *     "parentFolderId": "2bf470f5be194b319cdb2fvbu3278ff9"
 *    },
 *    context: {
 *      someKey1: "someValue1",
 *      someKey2: "someValue2"
 *    }
 *  }
 */

onVideoTranscoded( )

An event that fires when a video file has completed transcoding.

Description

The onVideoTranscoded() event handler runs when an uploaded video file has finished transcoding. It is fired some time after the onFileUploaded event.

The received FileEvent object contains information about the uploaded video and the upload context.

Note

Backend events don't work when previewing your site.

Syntax

function onVideoTranscoded(event: FileEvent): void
PARAMETERS
?
Values that you pass to a function.
event
The uploaded file information.

Examples

Receive an event when a video has been transcoded

// Place this code in the events.js file
// of your site's Backend section.

export function wixMedia_onVideoTranscoded(event) {
  let fileName = event.fileInfo.fileName;
}

/*  Full event object:
 *  {  
 *     "fileInfo": {  
 *        "mediaType": "video",
 *        "sourceUrl": "https://somedomain.com/img/original-name.mp4",
 *        "fileName": "9143bc_6aec991ee66c4c16a783433cc7dca232",
 *        "opStatus": "READY",
 *        "originalFileName": "original-name.mp4",
 *        "sizeInBytes": 1055736,
 *        "isPrivate": false
 *     },
 *     "context": {  
 *       "someKey1": "someValue1",
 *       "someKey2": "someValue2"
 *     }
 *  }
 */

FileEvent

An object representing an uploaded file and upload context.

See Also

onFileUploaded( ), onVideoTranscoded( )

Syntax

type FileEvent = {
  fileInfo: FileInfo
  context: Object
}
MEMBERS
?
The properties of an object.
fileInfo
Information about the uploaded file.
context
Object

An object of key:value string pairs that was sent when the file was uploaded.

Examples

Receive an event when a file has been uploaded

// Place this code in the events.js file
// of your site's Backend section.

export function wixMedia_onFileUploaded(event) {
  let fileName = event.fileInfo.fileName;
}

/*  Full event object:
 *  {
 *    "fileInfo": {
 *      "mediaType": "image",
 *      "height": 300,
 *      "sourceUrl": "https://somedomain.com/img/original-name.jpg",
 *      “fileName": "f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *      "mimeType": "image/jpeg",
 *      "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
 *      "opStatus": "READY",
 *      "labels": [
 *        "Blue",
 *        "Butterfly",
 *        "Turquoise"
 *      ],
 *     "fileUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
 *     "originalFileName": "original-name.jpg",
 *     "sizeInBytes": 51085,
 *     "isPrivate": false,
 *     "width": 300,
 *     "iconUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
 *     "parentFolderId": "2bf470f5be194b319cdb2fvbu3278ff9"
 *    },
 *    context: {
 *      someKey1: "someValue1",
 *      someKey2: "someValue2"
 *    }
 *  }
 */

Receive an event when a video has been transcoded

// Place this code in the events.js file
// of your site's Backend section.

export function wixMedia_onVideoTranscoded(event) {
  let fileName = event.fileInfo.fileName;
}

/*  Full event object:
 *  {  
 *     "fileInfo": {  
 *        "mediaType": "video",
 *        "sourceUrl": "https://somedomain.com/img/original-name.mp4",
 *        "fileName": "9143bc_6aec991ee66c4c16a783433cc7dca232",
 *        "opStatus": "READY",
 *        "originalFileName": "original-name.mp4",
 *        "sizeInBytes": 1055736,
 *        "isPrivate": false
 *     },
 *     "context": {  
 *       "someKey1": "someValue1",
 *       "someKey2": "someValue2"
 *     }
 *  }
 */