> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: searchFiles(options: SearchFilesOptions) # Method package: wixMediaV2 # Method menu location: wixMediaV2 --> files --> searchFiles # Method Link: https://dev.wix.com/docs/velo/apis/wix-media-v2/files/search-files.md # Method Description: Searches all folders in the Media Manager and returns a list of files that match the terms specified in the parameters.
If no parameters are specified, the endpoint returns all files in the `MEDIA_ROOT` folder. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Search files (dashboard page code) ```javascript import { files } from 'wix-media.v2'; async function mySearchFilesFunction() { try { const rootFiles = await files.searchFiles(); console.log('Files in MEDIA_ROOT', rootFiles); return rootFiles; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "files": [ * { * "_createdDate": "2023-07-16T08:54:05.000Z", * "_id": "w8ide0_ouulk5w0mdr9omjkwsfyn71g4mb1olcf~mv2.jpg", * "_updatedDate": "2023-07-16T08:54:05.000Z", * "displayName": "image2.jpg", * "hash": "800fae3e0cb7908518a391c25864436c", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [ * "label1", * "label2", * "label3", * "label4" * ], * "media": { * "image": { * "colors": { * "palette": [ * { * "rgb": { * "b": 47, * "g": 36, * "r": 31 * } * }, * { * "rgb": { * "b": 155, * "g": 153, * "r": 195 * } * }, * { * "rgb": { * "b": 141, * "g": 123, * "r": 138 * } * }, * { * "rgb": { * "b": 177, * "g": 161, * "r": 190 * } * }, * { * "rgb": { * "b": 179, * "g": 178, * "r": 217 * } * }, * { * "rgb": { * "b": 160, * "g": 176, * "r": 229 * } * }, * { * "rgb": { * "b": 176, * "g": 151, * "r": 162 * } * }, * { * "rgb": { * "b": 93, * "g": 78, * "r": 71 * } * }, * { * "rgb": { * "b": 45, * "g": 63, * "r": 107 * } * }, * { * "rgb": { * "b": 104, * "g": 88, * "r": 82 * } * } * ], * "prominent": { * "rgb": { * "b": 26, * "g": 36, * "r": 39 * } * } * }, * "faces": [], * "image": "wix:image://v1/w8ide0_ouulk5w0mdr9omjkwsfyn71g4mb1olcf~mv2.jpg/image2.jpg#originWidth=5833&originHeight=3894" * } * }, * "mediaType": "IMAGE", * "operationStatus": "READY", * "parentFolderId": "media-root", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "3013886", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/w8ide0_ouulk5w0mdr9omjkwsfyn71g4mb1olcf~mv2.jpg", * "url": "https://static.wixstatic.com/media/w8ide0_ouulk5w0mdr9omjkwsfyn71g4mb1olcf~mv2.jpg" * }, * { * "_createdDate": "2023-07-16T08:56:07.000Z", * "_id": "w8ide0_suuti24j47vesffndm8hkd651u72vp3f~mv2.jpg", * "_updatedDate": "2023-07-16T08:56:07.000Z", * "displayName": "image1.jpg", * "hash": "fef0ylitxcnlyzxf0nahu8rh3k0i5t85", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [ * "label1" * ], * "media": { * "image": { * "colors": { * "palette": [ * { * "rgb": { * "b": 26, * "g": 36, * "r": 39 * } * }, * { * "rgb": { * "b": 135, * "g": 125, * "r": 119 * } * }, * { * "rgb": { * "b": 208, * "g": 209, * "r": 208 * } * }, * { * "rgb": { * "b": 40, * "g": 108, * "r": 130 * } * }, * { * "rgb": { * "b": 133, * "g": 101, * "r": 75 * } * }, * { * "rgb": { * "b": 36, * "g": 78, * "r": 94 * } * }, * { * "rgb": { * "b": 178, * "g": 161, * "r": 148 * } * }, * { * "rgb": { * "b": 192, * "g": 177, * "r": 163 * } * }, * { * "rgb": { * "b": 159, * "g": 184, * "r": 208 * } * }, * { * "rgb": { * "b": 137, * "g": 159, * "r": 183 * } * } * ], * "prominent": { * "rgb": { * "b": 26, * "g": 36, * "r": 39 * } * } * }, * "faces": [], * "image": "wix:image://v1/w8ide0_suuti24j47vesffndm8hkd651u72vp3f~mv2.jpg/image1.jpg#originWidth=5616&originHeight=3744" * } * }, * "mediaType": "IMAGE", * "operationStatus": "READY", * "parentFolderId": "media-root", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "6312959", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/w8ide0_suuti24j47vesffndm8hkd651u72vp3f~mv2.jpg", * "url": "https://static.wixstatic.com/media/w8ide0_suuti24j47vesffndm8hkd651u72vp3f~mv2.jpg" * }, * { * "_createdDate": "2023-07-16T08:56:10.000Z", * "_id": "w8ide0_9yvsg5vv40flojo0120h0rz6ki4g0tur.zip", * "_updatedDate": "2023-07-16T08:56:10.000Z", * "displayName": "file1.zip", * "hash": "urm9iak1w39pk381ucb9kqjphya8loro", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [], * "media": { * "archive": { * "_id": "w8ide0_9yvsg5vv40flojo0120h0rz6ki4g0tur.zip", * "filename": "file1.zip", * "sizeInBytes": "49546083", * "url": "https://3ecba886-4267-11ee-be56-0242ac120002.usrfiles.com/archives/w8ide0_9yvsg5vv40flojo0120h0rz6ki4g0tur.zip" * } * }, * "mediaType": "ARCHIVE", * "operationStatus": "READY", * "parentFolderId": "media-root", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "49546083", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/48c4fbc47d7298cd4406936294b4c532.png", * "url": "https://3ecba886-4267-11ee-be56-0242ac120002.usrfiles.com/archives/w8ide0_9yvsg5vv40flojo0120h0rz6ki4g0tur.zip" * } * ], * "nextCursor": { * "cursors": { * "next": "" * }, * "hasNext": false * } * } */ ``` ## Search files (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; export const mySearchFilesFunction = webMethod(Permissions.Anyone, async () => { try { const elevatedSearchFiles = elevate(files.searchFiles); const rootFiles = await elevatedSearchFiles(); console.log('Files in MEDIA_ROOT', rootFiles); return rootFiles; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "files": [ * { * "_createdDate": "2023-07-16T08:54:05.000Z", * "_id": "w8ide0_ouulk5w0mdr9omjkwsfyn71g4mb1olcf~mv2.jpg", * "_updatedDate": "2023-07-16T08:54:05.000Z", * "displayName": "image2.jpg", * "hash": "800fae3e0cb7908518a391c25864436c", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [ * "label1", * "label2", * "label3", * "label4" * ], * "media": { * "image": { * "colors": { * "palette": [ * { * "rgb": { * "b": 47, * "g": 36, * "r": 31 * } * }, * { * "rgb": { * "b": 155, * "g": 153, * "r": 195 * } * }, * { * "rgb": { * "b": 141, * "g": 123, * "r": 138 * } * }, * { * "rgb": { * "b": 177, * "g": 161, * "r": 190 * } * }, * { * "rgb": { * "b": 179, * "g": 178, * "r": 217 * } * }, * { * "rgb": { * "b": 160, * "g": 176, * "r": 229 * } * }, * { * "rgb": { * "b": 176, * "g": 151, * "r": 162 * } * }, * { * "rgb": { * "b": 93, * "g": 78, * "r": 71 * } * }, * { * "rgb": { * "b": 45, * "g": 63, * "r": 107 * } * }, * { * "rgb": { * "b": 104, * "g": 88, * "r": 82 * } * } * ], * "prominent": { * "rgb": { * "b": 26, * "g": 36, * "r": 39 * } * } * }, * "faces": [], * "image": "wix:image://v1/w8ide0_ouulk5w0mdr9omjkwsfyn71g4mb1olcf~mv2.jpg/image2.jpg#originWidth=5833&originHeight=3894" * } * }, * "mediaType": "IMAGE", * "operationStatus": "READY", * "parentFolderId": "media-root", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "3013886", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/w8ide0_ouulk5w0mdr9omjkwsfyn71g4mb1olcf~mv2.jpg", * "url": "https://static.wixstatic.com/media/w8ide0_ouulk5w0mdr9omjkwsfyn71g4mb1olcf~mv2.jpg" * }, * { * "_createdDate": "2023-07-16T08:56:07.000Z", * "_id": "w8ide0_suuti24j47vesffndm8hkd651u72vp3f~mv2.jpg", * "_updatedDate": "2023-07-16T08:56:07.000Z", * "displayName": "image1.jpg", * "hash": "fef0ylitxcnlyzxf0nahu8rh3k0i5t85", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [ * "label1" * ], * "media": { * "image": { * "colors": { * "palette": [ * { * "rgb": { * "b": 26, * "g": 36, * "r": 39 * } * }, * { * "rgb": { * "b": 135, * "g": 125, * "r": 119 * } * }, * { * "rgb": { * "b": 208, * "g": 209, * "r": 208 * } * }, * { * "rgb": { * "b": 40, * "g": 108, * "r": 130 * } * }, * { * "rgb": { * "b": 133, * "g": 101, * "r": 75 * } * }, * { * "rgb": { * "b": 36, * "g": 78, * "r": 94 * } * }, * { * "rgb": { * "b": 178, * "g": 161, * "r": 148 * } * }, * { * "rgb": { * "b": 192, * "g": 177, * "r": 163 * } * }, * { * "rgb": { * "b": 159, * "g": 184, * "r": 208 * } * }, * { * "rgb": { * "b": 137, * "g": 159, * "r": 183 * } * } * ], * "prominent": { * "rgb": { * "b": 26, * "g": 36, * "r": 39 * } * } * }, * "faces": [], * "image": "wix:image://v1/w8ide0_suuti24j47vesffndm8hkd651u72vp3f~mv2.jpg/image1.jpg#originWidth=5616&originHeight=3744" * } * }, * "mediaType": "IMAGE", * "operationStatus": "READY", * "parentFolderId": "media-root", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "6312959", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/w8ide0_suuti24j47vesffndm8hkd651u72vp3f~mv2.jpg", * "url": "https://static.wixstatic.com/media/w8ide0_suuti24j47vesffndm8hkd651u72vp3f~mv2.jpg" * }, * { * "_createdDate": "2023-07-16T08:56:10.000Z", * "_id": "w8ide0_9yvsg5vv40flojo0120h0rz6ki4g0tur.zip", * "_updatedDate": "2023-07-16T08:56:10.000Z", * "displayName": "file1.zip", * "hash": "urm9iak1w39pk381ucb9kqjphya8loro", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [], * "media": { * "archive": { * "_id": "w8ide0_9yvsg5vv40flojo0120h0rz6ki4g0tur.zip", * "filename": "file1.zip", * "sizeInBytes": "49546083", * "url": "https://3ecba886-4267-11ee-be56-0242ac120002.usrfiles.com/archives/w8ide0_9yvsg5vv40flojo0120h0rz6ki4g0tur.zip" * } * }, * "mediaType": "ARCHIVE", * "operationStatus": "READY", * "parentFolderId": "media-root", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "49546083", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/48c4fbc47d7298cd4406936294b4c532.png", * "url": "https://3ecba886-4267-11ee-be56-0242ac120002.usrfiles.com/archives/w8ide0_9yvsg5vv40flojo0120h0rz6ki4g0tur.zip" * } * ], * "nextCursor": { * "cursors": { * "next": "" * }, * "hasNext": false * } * } */ ``` ## Search files with options ```javascript import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; /* Sample searchOptions value: * { * mediaTypes: ['IMAGE', 'ARCHIVE'], * search: 'river' * } */ async function mySearchFilesFunction(searchOptions) { try { const elevatedSearchFiles = elevate(files.searchFiles); const searchFiles = await elevatedSearchFiles(searchOptions); console.log('Search files result:', searchFiles); return searchFiles; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "files": [ * { * "_createdDate": "2023-07-16T08:54:05.000Z", * "_id": "w8ide0_j18vyi43l4adwd81tpioxumkojv3dg78~mv2.jpg", * "_updatedDate": "2023-07-19T08:43:58.000Z", * "displayName": "river", * "hash": "xa8k1btltmtn0nimi7a2diwdxd4aujku", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [ * "mountain stream", * "fresh water", * "river bank", * "natural scenery" * ], * "media": { * "image": { * "colors": { * "palette": [ * { * "rgb": { * "b": 41, * "g": 41, * "r": 24 * } * }, * { * "rgb": { * "b": 135, * "g": 105, * "r": 62 * } * }, * { * "rgb": { * "b": 195, * "g": 154, * "r": 105 * } * }, * { * "rgb": { * "b": 230, * "g": 190, * "r": 141 * } * }, * { * "rgb": { * "b": 96, * "g": 77, * "r": 44 * } * }, * { * "rgb": { * "b": 144, * "g": 135, * "r": 99 * } * }, * { * "rgb": { * "b": 64, * "g": 106, * "r": 64 * } * }, * { * "rgb": { * "b": 178, * "g": 131, * "r": 80 * } * }, * { * "rgb": { * "b": 247, * "g": 230, * "r": 185 * } * }, * { * "rgb": { * "b": 75, * "g": 145, * "r": 97 * } * } * ], * "prominent": { * "rgb": { * "b": 41, * "g": 41, * "r": 24 * } * } * }, * "faces": [], * "image": "wix:image://v1/w8ide0_j18vyi43l4adwd81tpioxumkojv3dg78~mv2.jpg/river#originWidth=5760&originHeight=3840" * } * }, * "mediaType": "IMAGE", * "operationStatus": "READY", * "parentFolderId": "media-root", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "3677628", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/w8ide0_j18vyi43l4adwd81tpioxumkojv3dg78~mv2.jpg", * "url": "https://static.wixstatic.com/media/w8ide0_j18vyi43l4adwd81tpioxumkojv3dg78~mv2.jpg" * }, * { * "_createdDate": "2023-07-16T08:56:10.000Z", * "_id": "w8ide0_r047t3x8bm46vlx5n1aeha1bdd7g4u1y.zip", * "_updatedDate": "2023-07-20T07:16:55.000Z", * "displayName": "riverpics", * "hash": "3vx3d37vf3j2ttxp61ax7wlt0iox58nh", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [], * "media": { * "archive": { * "_id": "w8ide0_r047t3x8bm46vlx5n1aeha1bdd7g4u1y.zip", * "filename": "riverpics", * "sizeInBytes": "49546083", * "url": "https://3ecba886-4267-11ee-be56-0242ac120002.usrfiles.com/archives/w8ide0_r047t3x8bm46vlx5n1aeha1bdd7g4u1y.zip" * } * }, * "mediaType": "ARCHIVE", * "operationStatus": "READY", * "parentFolderId": "media-root", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "49546083", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/48c4fbc47d7298cd4406936294b4c532.png", * "url": "https://3ecba886-4267-11ee-be56-0242ac120002.usrfiles.com/archives/w8ide0_r047t3x8bm46vlx5n1aeha1bdd7g4u1y.zip" * } * ], * "nextCursor": { * "cursors": { * "next": "" * }, * "hasNext": false * } * } */ ``` ## Bulk delete all files found in a chosen folder ```javascript /******************************************* * Backend code - bulk-delete-files.web.js * ******************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-business-tools.v2'; import { elevate } from 'wix-auth'; export const deleteFiles = webMethod(Permissions.Anyone, async (fileIds, options) => { try { const elevatedBulkDeleteFiles = elevate(files.bulkDeleteFiles); await elevatedBulkDeleteFiles(fileIds, options); console.log(`Permanently deleted files with ids: ${fileIds.toString()}.`); return true; } catch (error) { console.error(error); } }); export const searchFileIds = webMethod(Permissions.Anyone, async (parentFolderId) => { try { const options = { parentFolder: parentFolderId }; const elevatedSearchFiles = elevate(files.searchFiles); const returnedFiles = await elevatedSearchFiles(options); const fileIds = returnedFiles.map((file) => { return file._id; }); return fileIds; } catch (error) { console.error(error); } }); /************* * Page code * ************/ import { deleteFiles, searchFileIds } from 'backend/bulk-delete-files.web'; $w.onReady(() => { $w('#delete').onClick(async () => { const isDeletePermanently = $w('#deletePermanently').checked; const options = { permanent: isDeletePermanently }; const parentFolder = $w('#parentFolder').value; const fileIds = await searchFileIds(parentFolder); await deleteFiles(fileIds, options); $w('#successMessage').show(); }); }); ``` ---