Search.../

getDownloadUrl( )

Gets a temporary download URL with a token for a specified file in the Media Manager.

Description

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

Pass the file's URL in the fileUrl parameter, as returned in the fileUrl property of the getFileInfo(), importFile(), upload(), and listFiles() functions. When the download URL is clicked, the specified file downloads to your device.

You can use the getDownloadUrl() function to allow external clients to download a file from the Media Manager to their device.

This function provides a temporary URL for downloading a single file. If you need permanent download URLs for one or more files, use the downloadFiles() function.

Notes:

  • The download URL with the token is valid for a single file download only. getDownloadUrl() must be called for each file that you want to download.
  • This function's parameters are positional, and must be specified in the sequence shown in the syntax below. When specifying a parameter, use null as a placeholder for any unspecified parameters. For example, to specify downloadedFileName only, call getDownloadUrl(fileUrl, null, downloadedFileName, null).

Syntax

function getDownloadUrl(fileUrl: string, [expirationTime: number], [downloadedFileName: string], [expiredTokenRedirectUrl: string]): Promise<string>

getDownloadUrl Parameters

NAME
TYPE
DESCRIPTION
fileUrl
string

The file's Wix media URL in the following format: 'wix:image://v1/<uri>/<filename>#originWidth=<width>&originHeight=<height>[&watermark=<watermark_manifest_string>]'.

expirationTime
Optional
number

The time (in minutes) it takes for the download URL to expire. Defaults to 600. Limit is 525600 (1 year).

downloadedFileName
Optional
string

The downloaded file's name. Defaults to the file's name displayed in the Media Manager.

expiredTokenRedirectUrl
Optional
string

The redirect URL for when the download URL with a token has expired. Defaults to a 403 Forbidden response page.

Returns

Fulfilled - The file's download URL with a token.

Return Type:

Promise<string>

Was this helpful?

Get a temporary download URL

When clicked, the URL downloads a file from the Media Manager to your device.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { mediaManager } from 'wix-media-backend';
3
4// Sample fileUrl value: 'wix:image://v1/0abec0_51b1141c839c4d349035941cb9427ebe~mv2.jpg/child-on-bike.jpg#originWidth=768&originHeight=1024'
5
6export const myGetDownloadUrlFunction = webMethod(Permissions.Anyone, async (fileUrl) => {
7 const myFileDownloadUrl = await mediaManager.getDownloadUrl(fileUrl);
8 return myFileDownloadUrl;
9});
10
11
12/* Promise resolves to:
13 * "https://download-files.wix.com/_api/download/file?downloadToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJpc3MiO..."
14 */
Get a temporary download URL with an expiration date and redirect URL

When clicked, the URL downloads a file from the Media Manager to your device.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { mediaManager } from 'wix-media-backend';
3
4/* Sample fileUrl value: 'wix:image://v1/0abec0_51b1141c839c4d349035941cb9427ebe~mv2.jpg/child-on-bike.jpg#originWidth=768&originHeight=1024'
5 * Sample expirationTime value: 10
6 * Sample expiredTokenRedirectUrl value: 'https://www.my-redirect-url.com'
7 */
8
9export const myGetDownloadUrlFunction = webMethod(Permissions.Anyone, async (fileUrl, expirationTime, downloadedFileName, expiredTokenRedirectUrl) => {
10 const myFileDownloadUrl = await mediaManager.getDownloadUrl(fileUrl, expirationTime, null, expiredTokenRedirectUrl);
11 return myFileDownloadUrl;
12});
13
14
15/* Promise resolves to:
16 * "https://download-files.wix.com/_api/download/file?downloadToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJpc3MiO..."
17 */
Get a temporary download URL with an expiration date and redirect URL

When clicked, the URL downloads a file from the Media Manager to your device with the specified name.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { mediaManager } from 'wix-media-backend';
3
4/* Sample fileUrl value: 'wix:image://v1/0abec0_51b1141c839c4d349035941cb9427ebe~mv2.jpg/child-on-bike.jpg#originWidth=768&originHeight=1024'
5 * Sample expirationTime value: 10
6 * Sample downloadedFileName value: 'my-audio-clip-1'
7 * Sample expiredTokenRedirectUrl value: 'https://www.my-redirect-url.com'
8 */
9
10export const myGetDownloadUrlFunction = webMethod(Permissions.Anyone, async (fileUrl, expirationTime, downloadedFileName, expiredTokenRedirectUrl) => {
11 const myFileDownloadUrl = await mediaManager.getDownloadUrl(fileUrl, expirationTime, downloadedFileName, expiredTokenRedirectUrl);
12 return myFileDownloadUrl;
13});
14
15
16/* Promise resolves to:
17 * "https://download-files.wix.com/_api/download/file?downloadToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9eyJpc3MiO..."
18 */