> 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: listFiles(options: ListFilesOptions) # Method package: wixMediaV2 # Method menu location: wixMediaV2 --> files --> listFiles # Method Link: https://dev.wix.com/docs/velo/apis/wix-media-v2/files/list-files.md # Method Description: Retrieves a list of files in the Media Manager. To retrieve a list of files within a specific folder in the Media Manager, specify the folder's ID in the `parentFolderId` parameter. If no folder is specified, the method retrieves the list of files in the root folder of the Media Manager. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## List files in a specific folder (backend page code) ```javascript import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; /* Sample listOptions value: * { * parentFolderId : 'igje5u22nij3qkltzsnol37j3dnthvvh' * } */ async function myListFilesFunction(listOptions) { try { const elevatedListFiles = elevate(files.listFiles); const fileList = await elevatedListFiles(listOptions); console.log('Files in folder:', fileList); return fileList; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "files": [ * { * "_createdDate": "2023-07-16T08:56:07.000Z", * "_id": "w8ide0_f4dRFF610cKd7zkjVbaNddXgb181lXfg.pdf", * "_updatedDate": "2023-07-16T08:56:07.000Z", * "displayName": "file1.pdf", * "hash": "z3bxokp79p04ok6iiu9ao8srx5lrynfh", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [], * "media": { * "document": "wix:document://v1/w8ide0_f4dRFF610cKd7zkjVbaNddXgb181lXfg.pdf/file1.pdf" * }, * "mediaType": "DOCUMENT", * "operationStatus": "READY", * "parentFolderId": "igje5u22nij3qkltzsnol37j3dnthvvh", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "187199", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/it7ucst133nc8d9e0ff4d0nay1ucksc6.png", * "url": "https://3ecba886-4267-11ee-be56-0242ac120002.usrfiles.com/ugd/w8ide0_f4dRFF610cKd7zkjVbaNddXgb181lXfg.pdf" * }, * { * "_createdDate": "2023-07-16T08:56:07.000Z", * "_id": "w8ide0_170y03n3akmstnpt5jmsju89wvgs9tg4.pdf", * "_updatedDate": "2023-07-16T08:56:07.000Z", * "displayName": "file2.pdf", * "hash": "g6x41coggaystn596ndb09q1ecg036gk", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [], * "media": { * "document": "wix:document://v1/w8ide0_170y03n3akmstnpt5jmsju89wvgs9tg4.pdf/file2.pdf" * }, * "mediaType": "DOCUMENT", * "operationStatus": "READY", * "parentFolderId": "igje5u22nij3qkltzsnol37j3dnthvvh", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "81624", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/it7ucst133nc8d9e0ff4d0nay1ucksc6.png", * "url": "https://3ecba886-4267-11ee-be56-0242ac120002.usrfiles.com/ugd/w8ide0_170y03n3akmstnpt5jmsju89wvgs9tg4.pdf" * } * ], * "nextCursor": { * "cursors": { * "next": "" * }, * "hasNext": false * } * } */ ``` ## List files in a specific folder (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; /* Sample listOptions value: * { * parentFolderId : 'igje5u22nij3qkltzsnol37j3dnthvvh' * } */ export const myListFilesFunction = webMethod(Permissions.Anyone, async (listOptions) => { try { const elevatedListFiles = elevate(files.listFiles); const fileList = await elevatedListFiles(listOptions); console.log('Files in folder:', fileList); return fileList; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "files": [ * { * "_createdDate": "2023-07-16T08:56:07.000Z", * "_id": "w8ide0_f4dRFF610cKd7zkjVbaNddXgb181lXfg.pdf", * "_updatedDate": "2023-07-16T08:56:07.000Z", * "displayName": "file1.pdf", * "hash": "z3bxokp79p04ok6iiu9ao8srx5lrynfh", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [], * "media": { * "document": "wix:document://v1/w8ide0_f4dRFF610cKd7zkjVbaNddXgb181lXfg.pdf/file1.pdf" * }, * "mediaType": "DOCUMENT", * "operationStatus": "READY", * "parentFolderId": "igje5u22nij3qkltzsnol37j3dnthvvh", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "187199", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/it7ucst133nc8d9e0ff4d0nay1ucksc6.png", * "url": "https://3ecba886-4267-11ee-be56-0242ac120002.usrfiles.com/ugd/w8ide0_f4dRFF610cKd7zkjVbaNddXgb181lXfg.pdf" * }, * { * "_createdDate": "2023-07-16T08:56:07.000Z", * "_id": "w8ide0_170y03n3akmstnpt5jmsju89wvgs9tg4.pdf", * "_updatedDate": "2023-07-16T08:56:07.000Z", * "displayName": "file2.pdf", * "hash": "g6x41coggaystn596ndb09q1ecg036gk", * "internalTags": [ * "_fileOrigin_uploaded" * ], * "labels": [], * "media": { * "document": "wix:document://v1/w8ide0_170y03n3akmstnpt5jmsju89wvgs9tg4.pdf/file2.pdf" * }, * "mediaType": "DOCUMENT", * "operationStatus": "READY", * "parentFolderId": "igje5u22nij3qkltzsnol37j3dnthvvh", * "private": false, * "siteId": "3ecba886-4267-11ee-be56-0242ac120002", * "sizeInBytes": "81624", * "state": "OK", * "thumbnailUrl": "https://static.wixstatic.com/media/it7ucst133nc8d9e0ff4d0nay1ucksc6.png", * "url": "https://3ecba886-4267-11ee-be56-0242ac120002.usrfiles.com/ugd/w8ide0_170y03n3akmstnpt5jmsju89wvgs9tg4.pdf" * } * ], * "nextCursor": { * "cursors": { * "next": "" * }, * "hasNext": false * } * } */ ``` ## Generate a download url for all images in media ```javascript /******************************************** * Backend code - download-files-url.web.js * *******************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; export const generateDownloadUrl = webMethod(Permissions.Anyone, async (fileIds) => { try { const elevatedGenerateFilesDownloadUrl = elevate(files.generateFilesDownloadUrl) const generatedUrl = await elevatedGenerateFilesDownloadUrl(fileIds); return generatedUrl.downloadUrl; } catch (error) { console.error(error); } }); export const listImages = webMethod(Permissions.Anyone, async () => { const listOptions = { mediaTypes: ["IMAGE"] } try { const elevatedListFiles = elevate(files.listFiles) const images = await elevatedListFiles(listOptions); return images.files; } catch (error) { console.error(error); } }); /************* * Page code * ************/ import { listImages, generateDownloadUrl } from 'backend/download-files-url.web'; $w.onReady(() => { $w('#downloadFiles').disable(); getDownloadUrl(); }); async function getDownloadUrl() { const images = await listImages(); const imageIds = images.map((image) => { return image._id; }); const downloadUrl = await generateDownloadUrl(imageIds); $w('#downloadFiles').link = downloadUrl; await $w('#downloadFiles').enable(); } ``` ## Update a file's display name from visitor input ```javascript /************************************* * Backend code - update-file.web.js * ************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { files } from 'wix-media.v2'; import { elevate } from 'wix-auth'; export const updateFile = webMethod(Permissions.Anyone, async (fileId, file) => { try { const elevatedUpdateFileDescriptor = elevate(files.updateFileDescriptor); const updatedDescriptor = await elevatedUpdateFileDescriptor({ _id: fileId, ...file }); return updatedDescriptor; } catch (error) { console.error(error); } }); export const listImages = webMethod(Permissions.Anyone, async () => { const listOptions = { mediaTypes: ["IMAGE"] } try { const elevatedListFiles = elevate(files.listFiles) const images = await elevatedListFiles(listOptions); return images.files; } catch (error) { console.error(error); } }); /************* * Page code * ************/ import { updateFile, listImages } from 'backend/update-file.web'; $w.onReady(async () => { await populateImagesDropdown(); $w('#update').onClick(async () => { const imageId = $w('#imagesDropdown').value; const fileUpdates = { displayName: $w('#newDisplayName').value } const updatedLocation = await updateFile(imageId, fileUpdates); console.log('Display name successfully updated to:', updatedLocation.displayName) $w('#updateSuccessMsg').show(); }); }); async function populateImagesDropdown() { const images = await listImages(); const dropdownOptions = images.map((image) => { return { label: image.displayName, value: image._id }; }); $w('#imagesDropdown').options = dropdownOptions; }; ``` ---