Search.../

downloadFiles( )

Returns a download URL for downloading files from the Media Manager.

Description

The downloadFiles() function returns a Promise that resolves to a download URL for the specified file(s) in the Media Manager.

A compressed file is created and can be downloaded using the download URL. The compressed file can contain up to 1000 files.

Call the wix-location.to() function with the returned download URL as the external web address. This opens the Download bar in your browser.

This function provides a permanent URL for downloading one or more files. To get a temporary download URL for a single file, use the getDownloadUrl() function.

Note: The downloadFiles() function only allows you to download files with supported media types, and files that are explicitly listed in the Media Manager. Files with unsupported media types such as 'model', and files that aren't explicitly listed in the Media Manager such as default files in a gallery component, can't be downloaded using the downloadFiles() function. The supported media types are listed in the description for the mediaType return in the getFileInfo() function.

Syntax

function downloadFiles(fileUrls: Array<string>): Promise<string>

downloadFiles Parameters

NAME
TYPE
DESCRIPTION
fileUrls
Array<string>

A list of URLs for the file(s) to download. You can get the URLs with the fileUrl property of the listFiles() function.

Returns

Fulfilled - The download URL for the file(s). You can pass this URL to the wix-location.to() function to open the Download bar in the browser.

Return Type:

Promise<string>

Was this helpful?

Get a download URL for a single file

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { mediaManager } from 'wix-media-backend';
3
4export const myDownloadFilesFunction = webMethod(Permissions.Anyone, (fileUrls) => {
5 return mediaManager.downloadFiles(fileUrls)
6 .then((downloadUrl) => {
7 return downloadUrl;
8 })
9 .catch((error) => {
10 console.error(error);
11 });
12});
13
14/* Promise resolves to a URL similar to:
15 * "https://archive.wixmp.com/archive/wix/4c492536c61a495ca4b4526d71439a64"
16 */
Get and go to a download URL for all files

Copy Code
1/**************************************
2 * Page code *
3 **************************************/
4
5import wixLocationFrontend from 'wix-location-frontend';
6import { myListFilesFunction, myDownloadFilesFunction } from 'backend/media.web';
7
8$w.onReady(function () {
9
10 // ...
11
12 myListFilesFunction()
13 .then((myFiles) => {
14 const fileUrls = myFiles.map(file => file.fileUrl);
15 myDownloadFilesFunction(fileUrls)
16 .then((downloadUrl) => {
17 wixLocationFrontend.to(downloadUrl);
18 });
19 })
20 .catch((error) => {
21 console.error(error);
22 });
23});
24
25/**************************************
26 * Backend code - media.web.js *
27 **************************************/
28
29import { Permissions, webMethod } from 'wix-web-module';
30import { mediaManager } from 'wix-media-backend';
31
32export const myListFilesFunction = webMethod(Permissions.Anyone, () => {
33 return mediaManager.listFiles()
34 .then((myFiles) => {
35 return myFiles;
36 })
37 .catch((error) => {
38 console.error(error);
39 });
40});
41
42export const myDownloadFilesFunction = webMethod(Permissions.Anyone, (fileUrls) => {
43 return mediaManager.downloadFiles(fileUrls)
44 .then((downloadUrl) => {
45 return downloadUrl;
46 })
47 .catch((error) => {
48 console.error(error);
49 });
50});