> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# GenerateFileDownloadUrl

# Package: mediaManager

# Namespace: FilesService

# Method link: https://dev.wix.com/docs/api-reference/assets/media/media-manager/files/generate-file-download-url.md

## Permission Scopes:
Manage Media Manager: SCOPE.DC-MEDIA.MANAGE-MEDIAMANAGER

## Introduction

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

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

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

To generate a permanent URL for downloading a compressed file that contains multiple files in the Media Manager, call the Generate Files Download URL endpoint.
Since this is a permanent URL, it is less secure.
Therefore, to download private files, call the Generate File Download URL endpoint for each private file that you want to generate a download URL for.

---

## REST API

### Schema

```
 Method: generateFileDownloadUrl
 Description: Generates one or more temporary URLs for downloading a specific file in the Media Manager.  To download different assets of the file, specify the `assetKeys` parameter which generates a download URL for each asset. If no `assetKey` is specified, it defaults to `src`, which generates one download URL in the original file's format and quality.  Call this endpoint to grant external clients access to a private media file. Specify the `expirationInMinutes` parameter to set the URL expiration time, and the `expirationRedirectUrl` parameter to add a redirect url when the URL expires.  To generate a permanent URL for downloading a compressed file that contains multiple files in the Media Manager, call the Generate Files Download URL endpoint. Since this is a permanent URL, it is less secure. Therefore, to download private files, call the Generate File Download URL endpoint for each private file that you want to generate a download URL for.
 URL: https://www.wixapis.com/site-media/v1/files/generate-file-download-url
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  fileId
 Method parameters: 
   param name: assetKeys | type: array<assetKeys> | description: Keys for downloading different assets (format and quality) of a file. Default: `src`, key representing the original file's format and quality.  | validation: maxItems 100, maxLength 100
   param name: contentDisposition | type: ContentDisposition    
      - enum:
           ATTACHMENT - Using the link in the browser will download the file
           INLINE - Using the link in the browser will open the file in the browser
   param name: downloadFileName | type: downloadFileName | description: Temporary file name used to identify the file type. For example, a file named "myFile.jpeg" identifies as an "image/jpeg" file type. <br />  **Note:** The name that appears in the Media Manager is taken from the `filename` parameter in the Generate File Upload Url call.  | validation: maxLength 100
   param name: expirationInMinutes | type: expirationInMinutes | description: Time in minutes until the download URL expires. <br /> Default: `600` (10 hours). <br /> Limit: `525600` (1 year).  | validation: minimum 1, format int32
   param name: expirationRedirectUrl | type: expirationRedirectUrl | description: The redirect URL for when the temporary download URL with a token expires. <br /> Default: A 403 Forbidden response page.  | validation: format WEB_URL
   param name: fileId | type: fileId | description: File GUID.  You can also specify the file's Wix media URL. For example, `wix:image://v1/0abec0_b291a9349a0b4da59067f76287e386fb~mv2.jpg/leon.jpg#originWidth=3024&originHeight=4032`. Learn more [about the file GUID parameter](https://dev.wix.com/docs/api-reference/assets/media/media-manager/files/file-id.md). | required: true | validation: maxLength 1000
 Return type: GenerateFileDownloadUrlResponse
  - name: downloadUrls | type: array<DownloadUrl> | description: URL for downloading a specific file in the Media Manager.  | validation: maxItems 100
     - name: url | type: string | description: The file download URL.  | validation: format WEB_URL
     - name: assetKey | type: string | description: Key for downloading a different asset (format and quality) of a file. Default: `src`, key representing the original file's format and quality.  | validation: maxLength 100

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_ASSET_KEY | Description: The `assetKey` isn't valid for this file.


```

### Examples

### Generate a URL for downloading a file
```curl
curl -X POST \
  'https://www.wixapis.com/site-media/v1/files/generate-file-download-url' \
  -H 'Authorization: <AUTH>'
  -H 'Content-Type: application/json' \
  --data-binary '{
    "fileId": "4acbb8_7596aeebcf5c41eca01c0d99667ac967.mp3",
    "downloadFileName": "Gorillaz - Feel Good Inc.mp3",
    "expirationInMinutes": 60,
    "expirationRedirectUrl":"https://www.mysite.com/store",
    "assetKeys": ["320kbs.mp3"]
  }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.media.files.generateFileDownloadUrl(fileId, options)
 Description: Generates one or more temporary URLs for downloading a specific file in the Media Manager.  To download different assets of the file, specify the `assetKeys` parameter which generates a download URL for each asset. If no `assetKey` is specified, it defaults to `src`, which generates one download URL in the original file's format and quality.  Call this endpoint to grant external clients access to a private media file. Specify the `expirationInMinutes` parameter to set the URL expiration time, and the `expirationRedirectUrl` parameter to add a redirect url when the URL expires.  To generate a permanent URL for downloading a compressed file that contains multiple files in the Media Manager, call the Generate Files Download URL endpoint. Since this is a permanent URL, it is less secure. Therefore, to download private files, call the Generate File Download URL endpoint for each private file that you want to generate a download URL for.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  fileId
 Method parameters: 
   param name: fileId | type: string | description: File GUID.  You can also pass the files' Wix media URLs. For example, `["wix:image://v1/0abec0_b291a9349a0b4da59067f76287e386fb~mv2.jpg/leon.jpg#originWidth=3024&originHeight=4032"]`. Learn more in the File and Folder GUIDs article.  | required: true | validation: maxLength 1000
   param name: options | type: GenerateFileDownloadUrlOptions  none  
        - name: downloadFileName | type: string | description: Temporary file name used to identify the file type. For example, a file named "myFile.jpeg" identifies as an "image/jpeg" file type. <br />  **Note:** The name that appears in the Media Manager is taken from the `filename` parameter in the Generate File Upload Url call.  | validation: maxLength 100
        - name: expirationInMinutes | type: integer | description: Time in minutes until the download URL expires. <br /> Default: `600` (10 hours). <br /> Limit: `525600` (1 year).  | validation: minimum 1, format int32
        - name: expirationRedirectUrl | type: string | description: The redirect URL for when the temporary download URL with a token expires. <br /> Default: A 403 Forbidden response page.  | validation: format WEB_URL
        - name: assetKeys | type: array<string> | description: Keys for downloading different assets (format and quality) of a file. Default: `src`, key representing the original file's format and quality.  | validation: maxItems 100, maxLength 100
        - name: contentDisposition | type: ContentDisposition | description: Whether the link downloads the file or opens the file in the browser.  - `ATTACHMENT`: The link downloads the file. - `INLINE`: The link opens the file in the browser.  Default: `ATTACHMENT`  
             - enum:
             -     ATTACHMENT: Using the link in the browser will download the file
             -     INLINE: Using the link in the browser will open the file in the browser
 Return type: PROMISE<GenerateFileDownloadUrlResponse>
  - name: downloadUrls | type: array<DownloadUrl> | description: URL for downloading a specific file in the Media Manager.  | validation: maxItems 100
     - name: url | type: string | description: The file download URL.  | validation: format WEB_URL
     - name: assetKey | type: string | description: Key for downloading a different asset (format and quality) of a file. Default: `src`, key representing the original file's format and quality.  | validation: maxLength 100

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_ASSET_KEY | Description: The `assetKey` isn't valid for this file.


```

### Examples

### Generate a file download URL with options (with elevated permissions)
```javascript
import { files } from '@wix/media';
import { auth } from '@wix/essentials';

/* Sample fileId value: 'd4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg'
 * 
 * Sample options value: 
 * {
 *   assetKeys: ['320kbs.mp3'],
 *   downloadFileName: 'MyAudio.mp3',
 *   expirationInMinutes: '60',
 *   expirationRedirectUrl: 'www.example.com/store'
 * }
 */

export async function myGenerateFileDownloadUrlFunction(fileId, options) {
  try {
    const elevatedGenerateFileDonwloadUrl = auth.elevate(files.generateFileDownloadUrl)
    const result = await elevatedGenerateFileDonwloadUrl(fileId, options);

    const url = result.downloadUrls[0].url;
    return url;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "downloadUrls": [
 *     {
 *       "assetKey": "320kbs.mp3",
 *       "url": "https://download-files.wixmp.com/mp3/d4dde1_by0oqi7mrlyvhnodnhoywu6rr2egzujz-320.mp3?token=eyJhmHWBeilpRrgQGkzYAMcWQsyoISC4MSuG.eyJpc3MiOiJ1cm46YXBwOmU2NjYzMGU3MTRmMDQ5MGFhZWExZjE0OWIzYjY5ZTMyIiwic3ViIjoidXJuOmFwcDplNjY2MzBlNzE0ZjA0OTBhYWVhMWYxNDliM2I2OWUzMiIsImF1ZCI6WyJ1cm46c2VydmljZTpmaWxlLmRvd25sb2FkIl0sImlhdCI6MTY5MjI3MTQzMCwiZXhwIjoxNjkyMjcxNTYwLCJqdGkiOiJlZmZjZjdmMy1hZTdiLTQwMTUtYmIyZi00ZmE3ZDYzMGVlMTkiLCJvYmoiOltbeyJwYXRoIjoiL21wMy9kNGRkZTFfMjM2YzhlMDJmMTdlNDkyMjhlMjE3N2RjMjlkOWJkNzEtMzIwLm1wMyJ9XV0sInJlZCI6Imh0dHBzOi8vd3d3LmpodS5lZHUvIiwiZGlzIjp7ImZpbGVuYW1lIjoiR29yaWxsYXogLSBGZWVsIEdvb2QgSW5jLm1wMyIsInR5cGUiOiJhdHRhY2htZW50In19.qczf9WH3nz-tZ65D_RE8tzW-7o_cuq3b-oXX7QSYeAw"
 *     }
 *   ]
 * }
 */
```

### Generate a file download URL with options
```javascript
import { files } from '@wix/media';

/* Sample fileId value: 'd4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg'
 * 
 * Sample options value: 
 * {
 *   assetKeys: ['320kbs.mp3'],
 *   downloadFileName: 'MyAudio.mp3',
 *   expirationInMinutes: '60',
 *   expirationRedirectUrl: 'www.example.com/store'
 * }
 */

export async function myGenerateFileDownloadUrlFunction(fileId, options) {
  try {
    const result = await files.generateFileDownloadUrl(fileId, options);

    const url = result.downloadUrls[0].url;
    return url;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "downloadUrls": [
 *     {
 *       "assetKey": "320kbs.mp3",
 *       "url": "https://download-files.wixmp.com/mp3/d4dde1_by0oqi7mrlyvhnodnhoywu6rr2egzujz-320.mp3?token=eyJhmHWBeilpRrgQGkzYAMcWQsyoISC4MSuG.eyJpc3MiOiJ1cm46YXBwOmU2NjYzMGU3MTRmMDQ5MGFhZWExZjE0OWIzYjY5ZTMyIiwic3ViIjoidXJuOmFwcDplNjY2MzBlNzE0ZjA0OTBhYWVhMWYxNDliM2I2OWUzMiIsImF1ZCI6WyJ1cm46c2VydmljZTpmaWxlLmRvd25sb2FkIl0sImlhdCI6MTY5MjI3MTQzMCwiZXhwIjoxNjkyMjcxNTYwLCJqdGkiOiJlZmZjZjdmMy1hZTdiLTQwMTUtYmIyZi00ZmE3ZDYzMGVlMTkiLCJvYmoiOltbeyJwYXRoIjoiL21wMy9kNGRkZTFfMjM2YzhlMDJmMTdlNDkyMjhlMjE3N2RjMjlkOWJkNzEtMzIwLm1wMyJ9XV0sInJlZCI6Imh0dHBzOi8vd3d3LmpodS5lZHUvIiwiZGlzIjp7ImZpbGVuYW1lIjoiR29yaWxsYXogLSBGZWVsIEdvb2QgSW5jLm1wMyIsInR5cGUiOiJhdHRhY2htZW50In19.qczf9WH3nz-tZ65D_RE8tzW-7o_cuq3b-oXX7QSYeAw"
 *     }
 *   ]
 * }
 */
```

### Generate a file download URL (with elevated permissions)
```javascript
import { files } from '@wix/media';
import { auth } from '@wix/essentials';

const elevatedGenerateFileDownloadUrl = auth.elevate(files.generateFileDownloadUrl);

/* Sample fileId value: 'd4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg' */

async function myGenerateFileDownloadUrlFunction(fileId) {
  try {
    const result = await elevatedGenerateFileDownloadUrl(fileId);

    return result;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "downloadUrls": [
 *     {
 *       "assetKey": "src",
 *       "url": "https://download-files.wixmp.com/media/d4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1cm46YXBwOmU2NjYzMGU3MTRmMDQ5MGFhZWExZjE0OWIzYjY5ZTMyIiwic3ViIjoidXJuOmFwcDplNjY2MzBlNzE0ZjA0OTBhYWVhMWYxNDliM2I2OWUzMiIsImF1ZCI6WyJ1cm46c2VydmljZTpmaWxlLmRvd25sb2FkIl0sImlhdCI6MTY5MjAyMTMxNSwiZXhwIjoxNjkyMDU3MzI1LCJqdGkiOiJjZTA1MzUxYy1jNDA4LTRlYmMtYWI0OC04MWM0NWJlZDlkM2IiLCJvYmoiOltbeyJwYXRoIjoiL21lZGlhL2Q0ZGRlMV9kZWUxOGM5YWRhMTc0YTgxOGNjZjc1YzUwZTcyYzczOX5tdjIuanBnIn1dXSwiZGlzIjp7ImZpbGVuYW1lIjoibmVvbS1BZGtKLUxncFRyRS11bnNwbGFzaC5qcGciLCJ0eXBlIjoiYXR0YWNobWVudCJ9fQ.HfZiuG7UFavOpgh2T0lVn56oZ9NpLoV3z9Gmnqptt8Y"
 *     }
 *   ]
 * }
 */
```

### Generate a file download URL
```javascript
import { files } from '@wix/media';

/* Sample fileId value: 'd4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg' */

async function myGenerateFileDownloadUrlFunction(fileId) {
  try {
    const result = await files.generateFileDownloadUrl(fileId);

    return result;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "downloadUrls": [
 *     {
 *       "assetKey": "src",
 *       "url": "https://download-files.wixmp.com/media/d4dde1_dee18c9ada174a818ccf75c50e72c739~mv2.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ1cm46YXBwOmU2NjYzMGU3MTRmMDQ5MGFhZWExZjE0OWIzYjY5ZTMyIiwic3ViIjoidXJuOmFwcDplNjY2MzBlNzE0ZjA0OTBhYWVhMWYxNDliM2I2OWUzMiIsImF1ZCI6WyJ1cm46c2VydmljZTpmaWxlLmRvd25sb2FkIl0sImlhdCI6MTY5MjAyMTMxNSwiZXhwIjoxNjkyMDU3MzI1LCJqdGkiOiJjZTA1MzUxYy1jNDA4LTRlYmMtYWI0OC04MWM0NWJlZDlkM2IiLCJvYmoiOltbeyJwYXRoIjoiL21lZGlhL2Q0ZGRlMV9kZWUxOGM5YWRhMTc0YTgxOGNjZjc1YzUwZTcyYzczOX5tdjIuanBnIn1dXSwiZGlzIjp7ImZpbGVuYW1lIjoibmVvbS1BZGtKLUxncFRyRS11bnNwbGFzaC5qcGciLCJ0eXBlIjoiYXR0YWNobWVudCJ9fQ.HfZiuG7UFavOpgh2T0lVn56oZ9NpLoV3z9Gmnqptt8Y"
 *     }
 *   ]
 * }
 */
```

### generateFileDownloadUrl (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { files } from '@wix/media';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { files },
  // Include the auth strategy and host as relevant
});


async function generateFileDownloadUrl(fileId,options) {
  const response = await myWixClient.files.generateFileDownloadUrl(fileId,options);
};
```

---