> 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 # GenerateFilesDownloadUrl # Package: mediaManager # Namespace: FilesService # Method link: https://dev.wix.com/docs/api-reference/assets/media/media-manager/files/generate-files-download-url.md ## Permission Scopes: Manage Media Manager: SCOPE.DC-MEDIA.MANAGE-MEDIAMANAGER ## Introduction Generates a URL for downloading a compressed file containing specific files in the Media Manager. The compressed file can contain up to 1000 files. To generate a permanent URL for downloading a compressed file that contains multiple files in the Media Manager, call the Generate Files Download URL endpoint. Since this is a permanent URL, it is less secure. Therefore, to download private files, call the Generate File Download URL endpoint for each private file that you want to generate a download URL for. --- ## REST API ### Schema ``` Method: generateFilesDownloadUrl Description: Generates a URL for downloading a compressed file containing specific files in the Media Manager. The compressed file can contain up to 1000 files. To generate a permanent URL for downloading a compressed file that contains multiple files in the Media Manager, call the Generate Files Download URL endpoint. Since this is a permanent URL, it is less secure. Therefore, to download private files, call the Generate File Download URL endpoint for each private file that you want to generate a download URL for. URL: https://www.wixapis.com/site-media/v1/files/generate-download-url Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: fileIds Method parameters: param name: fileIds | type: array | description: IDs of the files to download. You can also specify the files' Wix media URLs. For example, `["wix:image://v1/0abec0_b291a9349a0b4da59067f76287e386fb~mv2.jpg/leon.jpg#originWidth=3024&originHeight=4032"]`. Learn more [about the file GUID parameter](https://dev.wix.com/docs/api-reference/assets/media/media-manager/files/file-id.md). | required: true Return type: GenerateFilesDownloadUrlResponse - name: downloadUrl | type: string | description: URL for downloading the compressed file containing the specified files in the Media Manager. ``` ### Examples ### Generate a URL for downloading a zip file containing the specified files ```curl curl -X POST \ 'https://www.wixapis.com/site-media/v1/files/generate-download-url' \ -H 'Authorization: ' -H 'Content-Type: application/json' \ --data-binary '{ "fileIds": ["4acbb8_7596aeebcf5c41eca01c0d99667ac967.mp3", "3vcbb7_7446aeebcf5c41eca01c0d99665bc866.mp3"] }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.mediaManager.FilesService.generateFilesDownloadUrl(fileIds) Description: Generates a URL for downloading a compressed file containing specific files in the Media Manager. The compressed file can contain up to 1000 files. To generate a permanent URL for downloading a compressed file that contains multiple files in the Media Manager, call the Generate Files Download URL endpoint. Since this is a permanent URL, it is less secure. Therefore, to download private files, call the Generate File Download URL endpoint for each private file that you want to generate a download URL for. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: fileIds Method parameters: param name: fileIds | type: array | description: IDs of the files to download. You can also pass the files' Wix media URLs. For example, `["wix:image://v1/0abec0_b291a9349a0b4da59067f76287e386fb~mv2.jpg/leon.jpg#originWidth=3024&originHeight=4032"]`. Learn more in the File and Folder GUIDs article. | required: true Return type: PROMISE - name: downloadUrl | type: string | description: URL for downloading the compressed file containing the specified files in the Media Manager. ``` ### Examples ### Generate a download url for all images in media (with $w) This is an example of a function running on page ready. The function lists all the images from media, and then uses their IDs to create a download url. ```javascript /*********************************************** * Backend code - download-files-url.web.js/ts * **********************************************/ import { Permissions, webMethod } from '@wix/web-methods'; import { files } from '@wix/media'; import { auth } from '@wix/essentials'; export const generateDownloadUrl = webMethod(Permissions.Anyone, async (fileIds) => { try { const elevatedGenerateFilesDownloadUrl = auth.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 = auth.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(); } ``` ### Generate a download url for multiple files (with elevated permissions) ```javascript import { files } from '@wix/media'; import { auth } from '@wix/essentials'; /* Sample fileIds value: * [ * 'd4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg', * 'd4dde1_84a62b7aeb874f73a7b736cad663d6f2.pdf', * 'd4dde1_e26da94b5cb440649ede0c433425449c~mv2.jpg' * ] */ const elevatedGenerateFilesDownloadUrl = auth.elevate(files.generateFilesDownloadUrl); async function myGenerateFilesDownloadUrlFunction(fileIds) { try { const generatedUrl = await elevatedGenerateFilesDownloadUrl(fileIds); const url = generatedUrl.downloadUrl; return url; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "downloadUrl": "https://archive.wixmp.com/archive/wix/38f69e35c283495187e85be0c8c06caf" * } */ ``` ### Generate a download url for multiple files ```javascript import { files } from '@wix/media'; /* Sample fileIds value: * [ * 'd4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg', * 'd4dde1_84a62b7aeb874f73a7b736cad663d6f2.pdf', * 'd4dde1_e26da94b5cb440649ede0c433425449c~mv2.jpg' * ] */ async function myGenerateFilesDownloadUrlFunction(fileIds) { try { const generatedUrl = await files.generateFilesDownloadUrl(fileIds); const url = generatedUrl.downloadUrl; return url; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "downloadUrl": "https://archive.wixmp.com/archive/wix/38f69e35c283495187e85be0c8c06caf" * } */ ``` ### generateFilesDownloadUrl (self-hosted) Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md). ```javascript import { createClient } from '@wix/sdk'; import { files } from '@wix/media'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { files }, // Include the auth strategy and host as relevant }); async function generateFilesDownloadUrl(fileIds) { const response = await myWixClient.files.generateFilesDownloadUrl(fileIds); }; ``` ---