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 thedownloadFiles()
function. The supported media types are listed in the description for themediaType
return in thegetFileInfo()
function.
Syntax
function downloadFiles(fileUrls: Array<string>): Promise<string>
downloadFiles Parameters
NAME
TYPE
DESCRIPTION
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:
Was this helpful?
1import {mediaManager} from 'wix-media-backend';23const fileUrls = ['https://static.wixstatic.com/media/4c47c6_49b0e6d2c19b4564a191f88f6748bbb3~mv2.png'];45export function myDownloadFilesFunction(fileUrls) {6 return mediaManager.downloadFiles(fileUrls)7 .then((downloadUrl) => {8 return downloadUrl;9 })10 .catch((error) => {11 console.error(error);12 })13}1415/* Promise resolves to a URL similar to:16 * "https://archive.wixmp.com/archive/wix/4c492536c61a495ca4b4526d71439a64"17 */
1/**************************************2 * Page code *3 **************************************/45 import wixLocationFrontend from 'wix-location-frontend';6 import { myDownloadFilesFunction, myListFilesFunction } from 'backend/media';78 $w.onReady(function () {910 // ...1112 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});2425/**************************************26 * Backend code - media.jsw *27 **************************************/2829import { mediaManager } from 'wix-media-backend';3031export function myListFilesFunction() {32 return mediaManager.listFiles()33 .then((myFiles) => {34 return myFiles;35 })36 .catch((error) => {37 console.error(error);38 });39}4041export function myDownloadFilesFunction(fileUrls) {42 return mediaManager.downloadFiles(fileUrls)43 .then((downloadUrl) => {44 return downloadUrl;45 })46 .catch((error) => {47 console.error(error);48 })49}