When you import or upload a file, it's not immediately available, meaning you can't manage or use the file straight away. Files can take time to import or upload and be processed. This is true even though the function used to import or upload a file returns a successful response.
To run code when a file finishes processing successfully, use the onFileUploaded()
event. For audio or video files, use onAudioTranscoded()
or onVideoTranscoded()
.
context
The import()
, upload()
, and getUploadUrl()
functions have a parameter called context
.
Arguments passed to this parameter are included only in the wix-media-backend
event bodies.
Use context
to pass information to the events that isn't contained in the file descriptor object.
context
use caseHere is a sample flow to show how you could use context
effectively.
There is a form on a site that sends site visitors a confirmation email with the details they submitted in the form. One of the form fields is an image URL. In the email, we want to send a Wix download URL for the image, not the original image URL. This means we can only send the email when the image file is ready to download.
To implement this, we use the following flow:
_id
.import()
to upload the image to the Media Manager. Include the context
parameter as follows:
onFileUploaded()
event in your events.js file, and implement the following steps to handle the event:
context.origin
is formBuilder
. We don't want to run this code if media was added from a different source._id
to retrieve the form details from the CMS.