Search.../

generateFolderDownloadUrl( )

Developer Preview

Generates a URL for downloading a compressed file containing a specific folder in the Media Manager.

Description

The generateFolderDownloadUrl() function returns a Promise that resolves to a download URL.

The compressed file can contain sub-folders, and up to 1000 files.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function generateFolderDownloadUrl(folderId: string): Promise<GenerateFolderDownloadUrlResponse>

generateFolderDownloadUrl Parameters

NAME
TYPE
DESCRIPTION
folderId
string

Folder ID.

Returns

Return Type:

Promise<
GenerateFolderDownloadUrlResponse
>
NAME
TYPE
DESCRIPTION
downloadUrl
string

URL for downloading a specific folder in the Media Manager.

Was this helpful?

Generate a folder download url

Copy Code
1import { folders } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4async function generateFolderDownloadUrl(folderId) {
5 try {
6 const elevatedGenerateFolderDownloadUrl = elevate(folders.generateFolderDownloadUrl);
7 const result = await elevatedGenerateFolderDownloadUrl(folderId);
8
9 const folderDownloadUrl = result.downloadUrl;
10 return folderDownloadUrl;
11 } catch (error) {
12 console.error(error);
13 // Handle the error
14 }
15}
16
17/* Promise resolves to:
18 * {
19 * "downloadUrl": "https://archive.wixmp.com/archive/wix/b367fe21877e4ef589cde5352a3a04af"
20 * }
21 */
Generate a folder download url for a chosen folder

This code is an example of a page on which a visitor chooses a folder from a dropdown list, and then receives a folder download url for that folder.

Copy Code
1/***************************************************
2 * Backend code - generate-folder-download-url.jsw *
3 **************************************************/
4
5import { folders } from 'wix-media.v2';
6import { elevate } from 'wix-auth';
7
8export async function listFolders() {
9 try {
10 const elevatedListFolders = elevate(folders.listFolders)
11 const foldersList = await elevatedListFolders();
12
13 return foldersList;
14 } catch (error) {
15 console.error(error);
16 }
17}
18
19async function generateDownloadUrl(folderId) {
20 try {
21 const elevatedGenerateFolderDownloadUrl = elevate(folders.generateFolderDownloadUrl);
22 const result = await elevatedGenerateFolderDownloadUrl(folderId);
23
24 const folderDownloadUrl = result.downloadUrl;
25 return folderDownloadUrl;
26 } catch (error) {
27 console.error(error);
28 }
29}
30
31/*************
32 * Page code *
33 ************/
34
35import { generateDownloadUrl, listFolders } from 'backend/generate-folder-download-url';
36
37$w.onReady(async () => {
38 await populateFoldersDropdown();
39
40 $w('#downloadFolder').onClick(async () => {
41 const folderId = $w('foldersDropdown').value;
42 const downloadUrl = await generateDownloadUrl(folderId);
43
44 $w('#downloadFolderBtn').link = downloadUrl;
45 $w('#downloadingFolderMsg').show();
46 });
47});
48
49async function populateFoldersDropdown() {
50 const folders = await listFolders();
51 const dropdownOptions = folders.map((folder) => {
52 return {
53 label: folder.displayName,
54 value: folder._id
55 };
56 });
57
58 $w('#foldersDropdown').options = dropdownOptions;
59};
60