Search.../

generateFileDownloadUrl( )

Generates one or more temporary URLs for downloading a specific file in the Media Manager.

Description

The generateFileDownloadUrl() function returns a Promise that resolves to an array containing download URLs for the assets specified in the options parameter.

To download different assets of the file, use the assetKeys parameter which generates a download URL for each asset. If no asset key is specified, it defaults to src, which generates one download URL in the original file's format and quality.

Use this endpoint to grant external clients access to a private media file. Use the expirationInMinutes parameter to set the URL expiration time, and the expirationRedirectUrl parameter to add a redirect URL when the URL expires.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function generateFileDownloadUrl(fileId: string, options: GenerateFileDownloadUrlOptions): Promise<GenerateFileDownloadUrlResponse>

generateFileDownloadUrl Parameters

NAME
TYPE
DESCRIPTION
fileId
string

File ID.

options
Optional
GenerateFileDownloadUrlOptions

Options to use when generating a file's download URL.

Returns

Return Type:

Promise<
GenerateFileDownloadUrlResponse
>
NAME
TYPE
DESCRIPTION
downloadUrls
Array<
DownloadUrl
>

URL for downloading a specific file in the Media Manager.

Was this helpful?

Generate a file download URL

Copy Code
1import { files } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample fileId value: 'd4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg' */
5
6async function myGenerateFileDownloadUrlFunction(fileId) {
7 try {
8 const elevatedGenerateFileDonwloadUrl = elevate(files.generateFileDownloadUrl)
9 const result = await elevatedGenerateFileDonwloadUrl(fileId);
10
11 return result;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16}
17
18/* Promise resolves to:
19 * {
20 * "downloadUrls": [
21 * {
22 * "assetKey": "src",
23 * "url": "https://download-files.wixmp.com/media/d4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1cm46YXBwOmU2NjYzMGU3MTRmMDQ5MGFhZWExZjE0OWIzYjY5ZTMyIiwic3ViIjoidXJuOmFwcDplNjY2MzBlNzE0ZjA0OTBhYWVhMWYxNDliM2I2OWUzMiIsImF1ZCI6WyJ1cm46c2VydmljZTpmaWxlLmRvd25sb2FkIl0sImlhdCI6MTY5MjAyMTMxNSwiZXhwIjoxNjkyMDU3MzI1LCJqdGkiOiJjZTA1MzUxYy1jNDA4LTRlYmMtYWI0OC04MWM0NWJlZDlkM2IiLCJvYmoiOltbeyJwYXRoIjoiL21lZGlhL2Q0ZGRlMV9kZWUxOGM5YWRhMTc0YTgxOGNjZjc1YzUwZTcyYzczOX5tdjIuanBnIn1dXSwiZGlzIjp7ImZpbGVuYW1lIjoibmVvbS1BZGtKLUxncFRyRS11bnNwbGFzaC5qcGciLCJ0eXBlIjoiYXR0YWNobWVudCJ9fQ.HfZiuG7UFavOpgh2T0lVn56oZ9NpLoV3z9Gmnqptt8Y"
24 * }
25 * ]
26 * }
27 */
Generate a file download URL with options

Copy Code
1import { files } from 'wix-media.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample fileId value: 'd4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg'
5 *
6 * Sample options value:
7 * {
8 * assetKeys: ['320kbs.mp3'],
9 * downloadFileName: 'MyAudio.mp3',
10 * expirationInMinutes: '60',
11 * expirationRedirectUrl: 'www.example.com/store'
12 * }
13 */
14
15async function myGenerateFileDownloadUrlFunction(fileId, options) {
16 try {
17 const elevatedGenerateFileDonwloadUrl = elevate(files.generateFileDownloadUrl)
18 const result = await elevatedGenerateFileDonwloadUrl(fileId, options);
19
20 const url = result.downloadUrls[0].url;
21 return url;
22 } catch (error) {
23 console.error(error);
24 // Handle the error
25 }
26}
27
28/* Promise resolves to:
29 * {
30 * "downloadUrls": [
31 * {
32 * "assetKey": "320kbs.mp3",
33 * "url": "https://download-files.wixmp.com/mp3/d4dde1_by0oqi7mrlyvhnodnhoywu6rr2egzujz-320.mp3?token=eyJhmHWBeilpRrgQGkzYAMcWQsyoISC4MSuG.eyJpc3MiOiJ1cm46YXBwOmU2NjYzMGU3MTRmMDQ5MGFhZWExZjE0OWIzYjY5ZTMyIiwic3ViIjoidXJuOmFwcDplNjY2MzBlNzE0ZjA0OTBhYWVhMWYxNDliM2I2OWUzMiIsImF1ZCI6WyJ1cm46c2VydmljZTpmaWxlLmRvd25sb2FkIl0sImlhdCI6MTY5MjI3MTQzMCwiZXhwIjoxNjkyMjcxNTYwLCJqdGkiOiJlZmZjZjdmMy1hZTdiLTQwMTUtYmIyZi00ZmE3ZDYzMGVlMTkiLCJvYmoiOltbeyJwYXRoIjoiL21wMy9kNGRkZTFfMjM2YzhlMDJmMTdlNDkyMjhlMjE3N2RjMjlkOWJkNzEtMzIwLm1wMyJ9XV0sInJlZCI6Imh0dHBzOi8vd3d3LmpodS5lZHUvIiwiZGlzIjp7ImZpbGVuYW1lIjoiR29yaWxsYXogLSBGZWVsIEdvb2QgSW5jLm1wMyIsInR5cGUiOiJhdHRhY2htZW50In19.qczf9WH3nz-tZ65D_RE8tzW-7o_cuq3b-oXX7QSYeAw"
34 * }
35 * ]
36 * }
37 */