CorvidReference

mediaManager

The mediaManager module contains functionality for working with the media that is stored in your site's Media Manager.

To use the Media Manager API, import mediaManager from the wix-media-backend module:

   import { mediaManager } from 'wix-media-backend';

Table of Contents

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
FileInfoAn object containing information about the file that was uploaded.
MediaOptionsAn object containing information about the media options of a file to upload.
MetadataOptionsAn object containing information about the metadata options of a file to upload.
UploadOptionsAn object containing information about the options of a file to upload.
UploadUrlAn object containing information about an upload URL.

getFileInfo( )

Gets a file's information from the Media Manager by name or URL.

Description

The getFileInfo() function returns a Promise that resolves to information about the specified file.

Pass one of the following in the file parameter:

  • Media Manager file name:
  • Wix URL:
    • As found in image type fields of database collections.
    • As returned in the fileUrl property from the importFile() and upload() functions.

Syntax

function getFileInfo(fileName: string): Promise<FileInfo>
PARAMETERS
?
Values that you pass to a function.
fileName
string
The Media Manager name or Wix URL of the file to get the information for.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<FileInfo>
Fulfilled - Information about the file.

Examples

Get a file's information

import { mediaManager } from 'wix-media-backend';

export async function getFileInfo(file) {
  return mediaManager.getFileInfo(file);
}

/* Returns a promise that resolves to:
 * {
 *   "fileName": "f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *   "fileUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
 *   "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
 *   "sizeInBytes": 51085,
 *   "mimeType": "image/jpeg",
 *   "mediaType": "image",
 *   "isPrivate": false,
 *   "iconUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
 *   "parentFolderId": "2bf470f5be194b319cdb2accc3278ff9",
 *   "originalFileName": "original-name.jpg",
 *   "sourceUrl": "https://somedomain.com/img/original-name.jpg",
 *   "width": 300,
 *   "height": 300,
 *   "labels": [
 *     "Blue",
 *     "Butterfly",
 *     "Turquoise"
 *   ],
 *   "opStatus": "READY"
 * }
 */

getFileUrl( )

Gets a file's URL from the Media Manager.

Description

The getFileUrl() function returns a Promise that resolves to the specified file's URL.

Pass a Media Manager file name in the fileName parameter as returned in the fileName property from the getFileInfo(), importFile(), and upload() functions.

Syntax

function getFileUrl(fileName: string): Promise<string>
PARAMETERS
?
Values that you pass to a function.
fileName
string
The Media Manager name of the file to get a URL for.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<string>
Fulfilled - The file's URL.

Examples

Get a file's URL

import { mediaManager } from 'wix-media-backend';

export async function getFileUrl(fileName) {
  return mediaManager.getFileUrl(fileName);
}

/* Returns a promise that resolves to:
 * "https://storage.googleapis.com/video.wixstatic.com/video/f6c0f9..."
 */

getUploadUrl( )

Gets an upload URL and a corresponding upload token.

Description

The getUploadUrl() function returns a Promise that resolves to an object containing an upload URL and a corresponding upload token.

Use getUploadUrl() to allow an external client to upload a file to your site's Media Manager.

The external client uploads a file by performing a POST operation to the returned URL using multipart/form-data encoding and sending the following data:

  • upload_token: The returned upload token.
  • file: An object containing:

    • name: The file name.
    • content: The content of the file.

    The POST will return the following:

    {
      "id": "<file id>",
      "path": "<file path>",
      "mimeType": "<file mime type>",
      "type": "<file type image|video|document|audio|shape>,
      "sizeInBytes": 1000,
      "acl": "<private|public>",
      "dateUpdated": "2017-02-14T15:24:17Z",
      "dateCreated": "2017-02-14T15:24:17Z"
    }

Syntax

function getUploadUrl(path: string, options: UploadOptions): Promise<UploadUrl>
PARAMETERS
?
Values that you pass to a function.
path
string

The path within the Media Manager where the file will be uploaded. If the path does not yet exist, the missing folders will be created.

options
Options to use when uploading the file.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<UploadUrl>
Fulfilled - The file's URL.

Examples

Get a URL and token to be used for uploading a file by POST

import { mediaManager } from 'wix-media-backend';

export function getUploadUrl() {
  return mediaManager.getUploadUrl(
    "/myUploadFolder/subfolder",
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/* Returns a promise that resolves to:
 * {
 *   uploadUrl: "https://files.wix.com/_ah/upload/OmEXRhIgZ..."
 *   uploadToken: "os0F1e3acdyLHSqYo-gvPlTsRX0LXRkCkHri128K..."
 * }
 */

getVideoPlaybackUrl( )

Gets a video file's playback URL from the Media Manager.

Description

The getVideoPlaybackUrl() function returns a Promise that resolves to the specified video file's playback URL.

Syntax

function getVideoPlaybackUrl(fileName: string, format: string): Promise<string>
PARAMETERS
?
Values that you pass to a function.
fileName
string
The Media Manager name of the file to get a URL for.
format
string
The format of the URL to get. Either "hls" or "dash".
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<string>
Fulfilled - The file's URL.

Examples

Get a URL to be used for video playback

import { mediaManager } from 'wix-media-backend';

export async function getVideoPlaybackUrl(fileName) {
  return mediaManager.getVideoPlaybackUrl(fileName, "hls");
}

/* Returns a promise that resolves to:
 * "https://repackager.wixmp.com/video.wixstatic.com/video/f6c0f9..."
 */

importFile( )

Imports a file to the Media Manager from a URL.

Description

The importFile() function returns a Promise that resolves to information about the newly imported file.

When the file is imported, When the file is imported the onFileUploaded() event is fired.

Video and audio files that have been imported are not immediately available to be used even after the Promise is resolved. Before they can be used, they must first undergo transcoding. When the transcoding is finished, the onVideoTranscoded() event is fired.

Syntax

function importFile(path: string, url: string, options: UploadOptions): Promise<FileInfo>
PARAMETERS
?
Values that you pass to a function.
path
string

The path within the Media Manager where the file will be uploaded. If the path does not yet exist, the missing folders will be created.

url
string
The file's URL.
options
Options to use when uploading a file
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<FileInfo>
Fulfilled - Information about the file that was uploaded.

Examples

Import a file

import { mediaManager } from 'wix-media-backend';

export function importFile(url) {
  return mediaManager.importFile(
    "/myImportFolder/subfolder",
    url,
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/* Returns a promise that resolves to:
 *
 * {
 *   "fileName": "f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *   "fileUrl": "media/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *   "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
 *   "sizeInBytes": 51085,
 *   "mimeType": "image/jpeg",
 *   "mediaType": "image",
 *   "isPrivate": false,
 *   "parentFolderId": "2bf470f5be194b319cdb2accc3278ff9",
 *   "originalFileName": "original-name.jpg",
 *   "sourceUrl": "https://somedomain.com/img/original-name.jpg",
 *   "opStatus": "IN-DOWNLOAD-QUEUE"
 * }
 */

upload( )

Uploads a file to the Media Manager.

Description

The upload() function returns a Promise that resolves to information about the newly uploaded file.

When the file is uploaded the onFileUploaded() event is fired.

Video and audio files that have been uploaded are not immediately available to be used even after the Promise is resolved. Before they can be used, they must first undergo transcoding. When the transcoding is finished, the onFileUploaded() event is fired a second time.

Syntax

function upload(path: string, fileContent: Buffer, fileName: string, options: UploadOptions): Promise<FileInfo>
PARAMETERS
?
Values that you pass to a function.
path
string

The path within the Media Manager where the file will be uploaded. If the path does not yet exist, the missing folders will be created.

fileContent
Buffer
Buffer containing the content to be uploaded.
fileName
string
Name of the file to upload. This name will be used in the Media Manager.
options
Options to use when uploading the file.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<FileInfo>
Fulfilled - Information about the file that was uploaded.

Examples

Upload a file

import { mediaManager } from 'wix-media-backend';

export function uploadImage(buffer) {
  return mediaManager.upload(
    "/myUploadFolder/subfolder",
    image,
    "myFileName.jpg",
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/*  Returns a promise that resolves to:
 *  {
 *    "fileName": "f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg",
 *    "mediaType": "image",
 *    "isPrivate": false,
 *    "sizeInBytes": 51085,
 *    "mimeType": "image/jpeg",
 *    "iconUrl": "wix:image://v1/f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg/myFileName.jpg#originWidth=300&originHeight=300",
 *    "fileUrl": "wix:image://v1/f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg/myFileName.jpg#originWidth=300&originHeight=300",
 *    "originalFileName": "myFileName.jpg",
 *    "hash": "bee2f8aab80b0d011499361c2eb189eb",
 *    "labels": [
 *      "Blue",
 *      "Butterfly",
 *      "Turquoise"
 *    ],
 *    "width": 300,
 *    "height": 300
 * }
 */

Upload a file from a URL

This example demonstrates how to upload a file using a custom upload button. It assumes you have a regular button on your page wired to an event handler.

It also assumes that you have installed the request-promise node module to your site. The example uses request-promise to create a Buffer containing the contents of the file to upload.

import { mediaManager } from 'wix-media-backend';
import rp from 'request-promise';

export function uploadImage(url) {
  return rp.get({ url, encoding: null })
    .then( (image) => {
      return mediaManager.upload(
        "/myUploadFolder/subfolder",
        image,
        "myFileName.jpg",
        {
          "mediaOptions": {
            "mimeType": "image/jpeg",
            "mediaType": "image"
          },
          "metadataOptions": {
            "isPrivate": false,
            "isVisitorUpload": false,
            "context": {
              "someKey1": "someValue1",
              "someKey2": "someValue2"
            }
          }
        }
      );
    } );
 }

/* Returns a promise that resolves to:
 * {
 *   fileName: "43io8d_4pf9jwff83ec478a811fe3f714a9c869"
 *   mediaType: "image"
 *   isPrivate: false
 *   sizeInBytes: 3631
 *   mimeType: "image/jpeg"
 *   iconUrl: "wix:image://v1/506418..."
 *   fileUrl: "wix:image://v1/506418..."
 *   originalFileName: "myFileName.jpeg"
 *   hash: "a3ac7ddabb263c2d00b73e8177d15c8d"
 * }
 */

FileInfo

An object containing information about the file that was uploaded.

See Also

getFileInfo( ), upload( ), importFile( ), onFileUploaded( ), onVideoTranscoded( )

Syntax

type FileInfo = {
  fileName: string
  fileUrl: string
  hash: string
  sizeInBytes: number
  mimeType: string
  mediaType: string
  isPrivate: boolean
  parentFolderId: string
  originalFileName: string
  opStatus: string
  sourceURL: string
  iconUrl: string
  labels: Array<string>
  height: string
  width: string
}
MEMBERS
?
The properties of an object.
fileName
string

File name of the file that was uploaded. This name is used when calling the getFileInfo(), getFileUrl(), and getVideoPlaybackUrl() functions.

fileUrl
string
URL of the file.
hash
string
File hash.
sizeInBytes
number
Size of the uploaded file in bytes.
mimeType
string

Mime type of the uploaded file.

mediaType
string

Type of the file that was uploaded. One of:

  • "audio"
  • "document"
  • "image"
  • "shape"
  • "video"
isPrivate
boolean

Whether the link to the uploaded file is public or private. Private links require a token to be used.

parentFolderId
string
ID of the uploaded files parent folder.
originalFileName
string

Name of the uploaded file. This is the name that appears in the Media Manager.

opStatus
string

Status of the file that was uploaded. One of:

  • "IN-DOWNLOAD-QUEUE"
  • "IN-QUEUE"
  • "READY"
sourceURL
string
URL where the file was uploaded from.
iconUrl
string
URL of the file's icon.
labels
Array<string>
List of labels assigned to the file by the Media Manager.
height
string
File height.
width
string
File width.

Examples

Get a file's information

import { mediaManager } from 'wix-media-backend';

export async function getFileInfo(file) {
  return mediaManager.getFileInfo(file);
}

/* Returns a promise that resolves to:
 * {
 *   "fileName": "f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *   "fileUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
 *   "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
 *   "sizeInBytes": 51085,
 *   "mimeType": "image/jpeg",
 *   "mediaType": "image",
 *   "isPrivate": false,
 *   "iconUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/original-name.jpg#originWidth=300&originHeight=300",
 *   "parentFolderId": "2bf470f5be194b319cdb2accc3278ff9",
 *   "originalFileName": "original-name.jpg",
 *   "sourceUrl": "https://somedomain.com/img/original-name.jpg",
 *   "width": 300,
 *   "height": 300,
 *   "labels": [
 *     "Blue",
 *     "Butterfly",
 *     "Turquoise"
 *   ],
 *   "opStatus": "READY"
 * }
 */

Upload a file

import { mediaManager } from 'wix-media-backend';

export function uploadImage(buffer) {
  return mediaManager.upload(
    "/myUploadFolder/subfolder",
    image,
    "myFileName.jpg",
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/*  Returns a promise that resolves to:
 *  {
 *    "fileName": "f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg",
 *    "mediaType": "image",
 *    "isPrivate": false,
 *    "sizeInBytes": 51085,
 *    "mimeType": "image/jpeg",
 *    "iconUrl": "wix:image://v1/f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg/myFileName.jpg#originWidth=300&originHeight=300",
 *    "fileUrl": "wix:image://v1/f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg/myFileName.jpg#originWidth=300&originHeight=300",
 *    "originalFileName": "myFileName.jpg",
 *    "hash": "bee2f8aab80b0d011499361c2eb189eb",
 *    "labels": [
 *      "Blue",
 *      "Butterfly",
 *      "Turquoise"
 *    ],
 *    "width": 300,
 *    "height": 300
 * }
 */

Import a file

import { mediaManager } from 'wix-media-backend';

export function importFile(url) {
  return mediaManager.importFile(
    "/myImportFolder/subfolder",
    url,
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/* Returns a promise that resolves to:
 *
 * {
 *   "fileName": "f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *   "fileUrl": "media/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *   "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
 *   "sizeInBytes": 51085,
 *   "mimeType": "image/jpeg",
 *   "mediaType": "image",
 *   "isPrivate": false,
 *   "parentFolderId": "2bf470f5be194b319cdb2accc3278ff9",
 *   "originalFileName": "original-name.jpg",
 *   "sourceUrl": "https://somedomain.com/img/original-name.jpg",
 *   "opStatus": "IN-DOWNLOAD-QUEUE"
 * }
 */

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"
 *    }
 *  }
 */

MediaOptions

An object containing information about the media options of a file to upload.

See Also

upload(), importFile(), getUploadUrl()

Syntax

type MediaOptions = {
  mediaType: string
  mimeType: string
}
MEMBERS
?
The properties of an object.
mediaType(Optional)
string

Type of the file to upload. One of:

  • "audio"
  • "document"
  • "image"
  • "shape"
  • "video"
mimeType(Optional)
string

Mime type of the file to import. The specified value must match the actual mime type of the file's content.

Examples

Upload a file

import { mediaManager } from 'wix-media-backend';

export function uploadImage(buffer) {
  return mediaManager.upload(
    "/myUploadFolder/subfolder",
    image,
    "myFileName.jpg",
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/*  Returns a promise that resolves to:
 *  {
 *    "fileName": "f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg",
 *    "mediaType": "image",
 *    "isPrivate": false,
 *    "sizeInBytes": 51085,
 *    "mimeType": "image/jpeg",
 *    "iconUrl": "wix:image://v1/f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg/myFileName.jpg#originWidth=300&originHeight=300",
 *    "fileUrl": "wix:image://v1/f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg/myFileName.jpg#originWidth=300&originHeight=300",
 *    "originalFileName": "myFileName.jpg",
 *    "hash": "bee2f8aab80b0d011499361c2eb189eb",
 *    "labels": [
 *      "Blue",
 *      "Butterfly",
 *      "Turquoise"
 *    ],
 *    "width": 300,
 *    "height": 300
 * }
 */

Import a file

import { mediaManager } from 'wix-media-backend';

export function importFile(url) {
  return mediaManager.importFile(
    "/myImportFolder/subfolder",
    url,
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/* Returns a promise that resolves to:
 *
 * {
 *   "fileName": "f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *   "fileUrl": "media/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *   "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
 *   "sizeInBytes": 51085,
 *   "mimeType": "image/jpeg",
 *   "mediaType": "image",
 *   "isPrivate": false,
 *   "parentFolderId": "2bf470f5be194b319cdb2accc3278ff9",
 *   "originalFileName": "original-name.jpg",
 *   "sourceUrl": "https://somedomain.com/img/original-name.jpg",
 *   "opStatus": "IN-DOWNLOAD-QUEUE"
 * }
 */

Get a URL and token to be used for uploading a file by POST

import { mediaManager } from 'wix-media-backend';

export function getUploadUrl() {
  return mediaManager.getUploadUrl(
    "/myUploadFolder/subfolder",
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/* Returns a promise that resolves to:
 * {
 *   uploadUrl: "https://files.wix.com/_ah/upload/OmEXRhIgZ..."
 *   uploadToken: "os0F1e3acdyLHSqYo-gvPlTsRX0LXRkCkHri128K..."
 * }
 */

MetadataOptions

An object containing information about the metadata options of a file to upload.

See Also

upload(), importFile(), getUploadUrl()

Syntax

type MetadataOptions = {
  isPrivate: boolean
  isVisitorUpload: boolean
  context: Object
}
MEMBERS
?
The properties of an object.
isPrivate(Optional)
boolean

Whether the link to the uploaded file will be public or private. Private links require a token to be used. Defaults to false.

isVisitorUpload(Optional)
boolean

Indicates if the file was uploaded by a site visitor. Files uploaded by visitors are tagged in the Media Manager as being added by a visitor. Defaults to true.

context(Optional)
Object

An object of key:value string pairs that is sent back in the onFileUploaded() event.

Examples

Upload a file

import { mediaManager } from 'wix-media-backend';

export function uploadImage(buffer) {
  return mediaManager.upload(
    "/myUploadFolder/subfolder",
    image,
    "myFileName.jpg",
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/*  Returns a promise that resolves to:
 *  {
 *    "fileName": "f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg",
 *    "mediaType": "image",
 *    "isPrivate": false,
 *    "sizeInBytes": 51085,
 *    "mimeType": "image/jpeg",
 *    "iconUrl": "wix:image://v1/f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg/myFileName.jpg#originWidth=300&originHeight=300",
 *    "fileUrl": "wix:image://v1/f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg/myFileName.jpg#originWidth=300&originHeight=300",
 *    "originalFileName": "myFileName.jpg",
 *    "hash": "bee2f8aab80b0d011499361c2eb189eb",
 *    "labels": [
 *      "Blue",
 *      "Butterfly",
 *      "Turquoise"
 *    ],
 *    "width": 300,
 *    "height": 300
 * }
 */

Import a file

import { mediaManager } from 'wix-media-backend';

export function importFile(url) {
  return mediaManager.importFile(
    "/myImportFolder/subfolder",
    url,
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/* Returns a promise that resolves to:
 *
 * {
 *   "fileName": "f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *   "fileUrl": "media/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *   "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
 *   "sizeInBytes": 51085,
 *   "mimeType": "image/jpeg",
 *   "mediaType": "image",
 *   "isPrivate": false,
 *   "parentFolderId": "2bf470f5be194b319cdb2accc3278ff9",
 *   "originalFileName": "original-name.jpg",
 *   "sourceUrl": "https://somedomain.com/img/original-name.jpg",
 *   "opStatus": "IN-DOWNLOAD-QUEUE"
 * }
 */

Get a URL and token to be used for uploading a file by POST

import { mediaManager } from 'wix-media-backend';

export function getUploadUrl() {
  return mediaManager.getUploadUrl(
    "/myUploadFolder/subfolder",
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/* Returns a promise that resolves to:
 * {
 *   uploadUrl: "https://files.wix.com/_ah/upload/OmEXRhIgZ..."
 *   uploadToken: "os0F1e3acdyLHSqYo-gvPlTsRX0LXRkCkHri128K..."
 * }
 */

UploadOptions

An object containing information about the options of a file to upload.

Syntax

type UploadOptions = {
  mediaOptions: MediaOptions
  metadataOptions: MetadataOptions
}
MEMBERS
?
The properties of an object.
mediaOptions(Optional)
Media options of the file to upload.
metadataOptions(Optional)
Metadata options of the file to upload.

Examples

Upload a file

import { mediaManager } from 'wix-media-backend';

export function uploadImage(buffer) {
  return mediaManager.upload(
    "/myUploadFolder/subfolder",
    image,
    "myFileName.jpg",
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/*  Returns a promise that resolves to:
 *  {
 *    "fileName": "f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg",
 *    "mediaType": "image",
 *    "isPrivate": false,
 *    "sizeInBytes": 51085,
 *    "mimeType": "image/jpeg",
 *    "iconUrl": "wix:image://v1/f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg/myFileName.jpg#originWidth=300&originHeight=300",
 *    "fileUrl": "wix:image://v1/f6c0f9_g2ae28cf29ec4639bc45698fee57cf56~mv2.jpg/myFileName.jpg#originWidth=300&originHeight=300",
 *    "originalFileName": "myFileName.jpg",
 *    "hash": "bee2f8aab80b0d011499361c2eb189eb",
 *    "labels": [
 *      "Blue",
 *      "Butterfly",
 *      "Turquoise"
 *    ],
 *    "width": 300,
 *    "height": 300
 * }
 */

Import a file

import { mediaManager } from 'wix-media-backend';

export function importFile(url) {
  return mediaManager.importFile(
    "/myImportFolder/subfolder",
    url,
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/* Returns a promise that resolves to:
 *
 * {
 *   "fileName": "f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *   "fileUrl": "media/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg",
 *   "hash": "Ew00kXbu4Zt33rzjcWa6Ng==",
 *   "sizeInBytes": 51085,
 *   "mimeType": "image/jpeg",
 *   "mediaType": "image",
 *   "isPrivate": false,
 *   "parentFolderId": "2bf470f5be194b319cdb2accc3278ff9",
 *   "originalFileName": "original-name.jpg",
 *   "sourceUrl": "https://somedomain.com/img/original-name.jpg",
 *   "opStatus": "IN-DOWNLOAD-QUEUE"
 * }
 */

Get a URL and token to be used for uploading a file by POST

import { mediaManager } from 'wix-media-backend';

export function getUploadUrl() {
  return mediaManager.getUploadUrl(
    "/myUploadFolder/subfolder",
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/* Returns a promise that resolves to:
 * {
 *   uploadUrl: "https://files.wix.com/_ah/upload/OmEXRhIgZ..."
 *   uploadToken: "os0F1e3acdyLHSqYo-gvPlTsRX0LXRkCkHri128K..."
 * }
 */

UploadUrl

An object containing information about an upload URL.

See Also

getUploadUrl( )

Syntax

type UploadUrl = {
  uploadUrl: string
  uploadToken: string
}
MEMBERS
?
The properties of an object.
uploadUrl
string
The URL to POST a file to.
uploadToken
string
The token to use with the file POST.

Examples

Get a URL and token to be used for uploading a file by POST

import { mediaManager } from 'wix-media-backend';

export function getUploadUrl() {
  return mediaManager.getUploadUrl(
    "/myUploadFolder/subfolder",
    {
      "mediaOptions": {
        "mimeType": "image/jpeg",
        "mediaType": "image"
      },
      "metadataOptions": {
        "isPrivate": false,
        "isVisitorUpload": false,
        "context": {
          "someKey1": "someValue1",
          "someKey2": "someValue2"
        }
      }
    }
  );
}

/* Returns a promise that resolves to:
 * {
 *   uploadUrl: "https://files.wix.com/_ah/upload/OmEXRhIgZ..."
 *   uploadToken: "os0F1e3acdyLHSqYo-gvPlTsRX0LXRkCkHri128K..."
 * }
 */