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 {mediaManager} from 'wix-media-backend';
2
3/* Sample fileUrls value:
4 * [
5 * "wix:image://v1/4c47c6_49b0e6d2c19b4564a191f88f6748bbb3~mv2.png/cat9.png#originWidth=319&originHeight=206"
6 * ]
7 */
8
9export function myDownloadFilesFunction(fileUrls) {
10 return mediaManager.downloadFiles(fileUrls)
11 .then((downloadUrl) => {
12 return downloadUrl;
13 })
14 .catch((error) => {
15 console.error(error);
16 })
17}
18
19/* Promise resolves to a URL similar to:
20 * "https://archive.wixmp.com/archive/wix/4c492536c61a495ca4b4526d71439a64"
21 */
Get and go to a download URL for all files

Copy Code
1/**************************************
2 * Page code *
3 **************************************/
4
5 import wixLocationFrontend from 'wix-location-frontend';
6 import { myDownloadFilesFunction, myListFilesFunction } from 'backend/media';
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.jsw *
27 **************************************/
28
29import { mediaManager } from 'wix-media-backend';
30
31export function myListFilesFunction() {
32 return mediaManager.listFiles()
33 .then((myFiles) => {
34 return myFiles;
35 })
36 .catch((error) => {
37 console.error(error);
38 });
39}
40
41export function myDownloadFilesFunction(fileUrls) {
42 return mediaManager.downloadFiles(fileUrls)
43 .then((downloadUrl) => {
44 return downloadUrl;
45 })
46 .catch((error) => {
47 console.error(error);
48 })
49}