Search.../

generateFilesDownloadUrl( )

Developer Preview

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

Description

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

The compressed file can contain 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 generateFilesDownloadUrl(fileIds: Array<string>): Promise<GenerateFilesDownloadUrlResponse>

generateFilesDownloadUrl Parameters

NAME
TYPE
DESCRIPTION
fileIds
Array<
string
>

IDs of the files to download.

Returns

Return Type:

Promise<
GenerateFilesDownloadUrlResponse
>
NAME
TYPE
DESCRIPTION
downloadUrl
string

URL for downloading the compressed file containing the specified files in the Media Manager.

Was this helpful?

Generate a download url for multiple files

Copy Code
1import { files } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample fileIds value:
5 * [
6 * 'd4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg',
7 * 'd4dde1_84a62b7aeb874f73a7b736cad663d6f2.pdf',
8 * 'd4dde1_e26da94b5cb440649ede0c433425449c~mv2.jpg'
9 * ]
10 */
11
12async function myGenerateFilesDownloadUrlFunction(fileIds) {
13 try {
14 const elevatedGenerateFilesDownloadUrl = elevate(files.generateFilesDownloadUrl)
15 const generatedUrl = await elevatedGenerateFilesDownloadUrl(fileIds);
16
17 const url = generatedUrl.downloadUrl;
18 return url;
19 } catch (error) {
20 console.error(error);
21 // Handle the error
22 }
23}
24
25/* Promise resolves to:
26 * {
27 * "downloadUrl": "https://archive.wixmp.com/archive/wix/38f69e35c283495187e85be0c8c06caf"
28 * }
29 */
Generate a download url for all images in media

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.

Copy Code
1/**************************************
2 * Backend code - download-files-url.jsw *
3 *************************************/
4
5import { files } from 'wix-media.v2';
6import { elevate } from 'wix-auth';
7
8export async function generateDownloadUrl(fileIds) {
9 try {
10 const elevatedGenerateFilesDownloadUrl = elevate(files.generateFilesDownloadUrl)
11 const generatedUrl = await elevatedGenerateFilesDownloadUrl(fileIds);
12
13 return generatedUrl.downloadUrl;
14 } catch (error) {
15 console.error(error);
16 }
17}
18
19export async function listImages() {
20 const listOptions = {
21 mediaTypes: ["IMAGE"]
22 }
23
24 try {
25 const elevatedListFiles = elevate(files.listFiles)
26 const images = await elevatedListFiles(listOptions);
27
28 return images.files;
29 } catch (error) {
30 console.error(error);
31 }
32}
33
34
35/*************
36 * Page code *
37 ************/
38
39import { listImages, generateDownloadUrl } from 'backend/download-files-url';
40
41$w.onReady(() => {
42 $w('#downloadFiles').disable();
43 getDownloadUrl();
44});
45
46async function getDownloadUrl() {
47 const images = await listImages();
48
49 const imageIds = images.map((image) => {
50 return image._id;
51 });
52 const downloadUrl = await generateDownloadUrl(imageIds);
53
54 $w('#downloadFiles').link = downloadUrl;
55 await $w('#downloadFiles').enable();
56}