importFile( )


Imports a file to the Media Manager from a URL.

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

Video and audio files that have been imported aren't immediately available to be used even after the Promise is resolved. Before they can be used, they must first undergo transcoding. The onFileUploaded() event is triggered when an imported file has been uploaded and before the transcoding is finished. As a result, some properties such as the fileUrl may not initially appear in the returns.

Note: Receiving a response does not indicate that the import is complete. To run code when the import finishes, implement the relevant event. See Importing and Uploading Files to learn more.

Method Declaration
Copy
function importFile(
  path: string,
  url: string,
  options: UploadOptions,
): Promise<FileInfo>;
Method Parameters
pathstringRequired

The path within the Media Manager where the file will be uploaded. If the path doesn't yet exist, the missing folders will be created, for example: /media/files.

If metadataOptions.isVisitorUpload is true (default), the visitor-uploads folder is the root of the file path, in this case, visitor-uploads/media/files/.


urlstringRequired

The file's external URL, where it was imported from.


optionsUploadOptionsRequired

Options to use when uploading a file

Returns
Return Type:Promise<FileInfo>
Import a file
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { mediaManager } from "wix-media-backend"; export const importFile = webMethod(Permissions.Anyone, (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: * * { * "fileUrl": "wix:image://v1/f6c0f9_tg439f4475a749e181dd14407fdbd37e~mv2.jpg/imported-pic.png#originWidth=319&originHeight=206", * "hash": "Ew00kXbu4Zt33rzjcWa6Ng==", * "sizeInBytes": 51085, * "mimeType": "image/jpeg", * "mediaType": "image", * "isPrivate": false, * "parentFolderId": "2bf470f5be194b319cdb2accc3278ff9", * "originalFileName": "my-image.jpg", * "sourceUrl": "https://somedomain.com/img/original-name.jpg", * "opStatus": "IN-DOWNLOAD-QUEUE" * } */
Did this help?

listFiles( )


Gets a list of files from the Media Manager by parentFolderId (or root).

The listFiles() function returns a Promise that resolves to information about the files in the folder.

To get a list of files within a specific folder in the Media Manager, pass the folder's ID in the parentFolderId parameter. If no folder is specified, the listFiles() function returns the list of files in the root folder of the Media Manager.

Notes:

  • This function's parameters are positional, and must be specified in the sequence shown in the syntax below. When specifying a parameter, use null as a placeholder for any unspecified parameters. For example, to specify parentFolderId only, call listFiles(filters, null, null). For example, to specify sorting only, call listFiles(null, sorting, null).

  • The listFiles() function only gets a list of files with supported media types, and that are explicitly listed in the Media Manager. Files with unsupported media types such as 'model', and files that aren't explicitly listed in the Media Manager such as default files in a gallery component, aren't listed when calling the listFiles() function. The supported media types are listed in the description for the mediaType return in the getFileInfo() function.

Method Declaration
Copy
function listFiles(
  filters: FileFilterOptions,
  sorting: SortingOptions,
  paging: PagingOptions,
): Promise<Array<File>>;
Method Parameters
filtersFileFilterOptions

File filter options.


sortingSortingOptions

Sorting options.


pagingPagingOptions

Paging options.

Returns
Return Type:Promise<Array<File>>
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { mediaManager } from "wix-media-backend"; const filters = { parentFolderId: "8a3be85ea03e4b8b82f2f9c989557c3d", }; export const myListFilesFunction = webMethod(Permissions.Anyone, () => { return mediaManager .listFiles(filters, null, null) .then((myFiles) => { const originalFileName = myFiles[0].originalFileName; const fileUrl = myFiles[1].fileUrl; return myFiles; }) .catch((error) => { console.error(error); }); }); /* Returns a promise that resolves to: * [{ * "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": "8a3be85ea03e4b8b82f2f9c989557c3d", * "originalFileName": "original-name1.jpg", * "width": 300, * "height": 300, * "labels": [ * "Blue", * "Butterfly", * "Turquoise" * ], * "_createdDate": "Sun December 4 2020 10:56:09 GMT+0300", * "_updatedDate": "Wed May 12 2021 14:27:15 GMT+0300" * }, * { * "fileUrl": "wix:image://v1/8b7eef_47332c4ae5b74db89d86d5d9e0cd303b~mv2.png/Screen%20Shot%202021-05-19%20at%209.59.29.png#originWidth=984&originHeight=1230", * "hash": "93fea6d1c6f7b10e24a729b0402ac152", * "sizeInBytes": 232794, * "mimeType": "image/jpeg", * "mediaType": "image", * "isPrivate": false, * "iconUrl": "wix:image://v1/8b7eef_47332c4ae5b74db89d86d5d9e0cd303b~mv2.png/Screen%20Shot%202021-05-19%20at%209.59.29.png#originWidth=984&originHeight=1230", * "parentFolderId": "8a3be85ea03e4b8b82f2f9c989557c3d", * "originalFileName": "original-name2.jpg", * "sourceUrl": "https://somedomain.com/img/original-name.jpg", * "width": 984, * "height": 221, * "labels": [ * "Font", * "Type", * "Write" * ], * "opStatus": "READY", * "_createdDate": "Tues January 22 2020 12:56:02 GMT+0300", * "_updatedDate": "Fri October 9 2020 04:56:22 GMT+0300" * }] */
Did this help?

listFolders( )


Gets a list of folders from the Media Manager by parentFolderId (or root).

The listFolders() function returns a Promise that resolves to information about the folders in the folder.

To get a list of folders within a specific folder in the Media Manager, pass the folder's ID in the parentFolderId parameter. If no folder is specified, the listFolders() function returns the list of folders in the root folder of the Media Manager.

Note: This function's parameters are positional, and must be specified in the sequence shown in the syntax below. When specifying a parameter, use null as a placeholder for any unspecified parameters. For example, to specify parentFolderId only, call listFolders(filters, null, null). For example, to specify sorting only, call listFolders(null, sorting, null).

Method Declaration
Copy
function listFolders(
  filters: FolderFilterOptions,
  sorting: SortingOptions,
  paging: PagingOptions,
): Promise<Array<FolderInfo>>;
Method Parameters
filtersFolderFilterOptions

Folder filter options.


sortingSortingOptions

Sorting options.


pagingPagingOptions

Paging options.

Returns
Return Type:Promise<Array<FolderInfo>>
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { mediaManager } from "wix-media-backend"; const filters = { parentFolderId: "8a3be85ea03e4b8b82f2f9c989557c3d", }; export const myListFoldersFunction = webMethod(Permissions.Anyone, () => { return mediaManager .listFolders(filters, null, null) .then((myFolders) => { const folderName = myFolders[0].folderName; const updatedDate = myFolders[1]._updatedDate; return myFolders; }) .catch((error) => { console.error(error); }); }); /* Returns a promise that resolves to: * [{ * "folderId": "1bf317e889264736b5acb367415fad8e", * "folderName": "greatfolder1", * "parentFolderId": "8a3be85ea03e4b8b82f2f9c989557c3d", * "_createdDate": "Sun December 4 2020 14:56:15 GMT+0300", * "_updatedDate": "Wed May 12 2021 14:56:15 GMT+0300" * }, * { * "folderId": "2fj678p889264736b5acb367415fad5g", * "folderName": "greatfolder2", * "parentFolderId": "8a3be85ea03e4b8b82f2f9c989557c3d", * "_createdDate": "Sun December 4 2020 14:56:15 GMT+0300", * "_updatedDate": "Wed May 12 2021 14:56:15 GMT+0300" * }] */
Did this help?

moveFilesToTrash( )


Moves single or multiple files to the Media Manager's trash.

The moveFilesToTrash() function returns a Promise that resolves when the file(s) are moved to the Media Manager's trash.

Moving many files to trash at once is an asynchronous action. It may take some time for the results to be seen in the Media Manager.

Use the Media Manager to restore or permanently delete the trashed files.

Attempting to move already-trashed files to trash again doesn't result in an error.

Method Declaration
Copy
function moveFilesToTrash(fileUrls: Array<string>): Promise<void>;
Method Parameters
fileUrlsArray<string>Required

URLs of the files to move to trash.

JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { mediaManager } from "wix-media-backend"; /* Sample fileUrls array: * [ * "wix:image://v1/4c47c6_85e8701ae75d4bb48436aecbd28dda5a~mv2.png/cat8.png#originWidth=337&originHeight=216", * "wix:image://v1/4c47c6_49b0e6d2c19b4564a191f88f6748bbb3~mv2.png/cat9.png#originWidth=319&originHeight=206" * ] */ export const myMoveFilesToTrashFunction = webMethod( Permissions.Anyone, (fileUrls) => { return mediaManager .moveFilesToTrash(fileUrls) .then(() => { console.log("Success! Files have been trashed."); }) .catch((error) => { console.error(error); }); }, ); /** * Returns a promise that resolves to <void> **/
Did this help?