> 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`).
> - 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: richContent

# Namespace: RicosDocument

# Method link: https://dev.wix.com/docs/api-reference/assets/rich-content/ricos-documents/generate-file-download-url.md

## Permission Scopes:
Manage Ricos Document: SCOPE.DC-RICOS.MANAGE-DOCUMENTS

## Introduction

Generates a temporary URL for downloading the file referenced by a file node in a Ricos document.

Specify the file node's `fileData.src.id` as `fileId`. The returned URL downloads the original file
as an attachment and expires after 10 hours. Private files are supported, so you can use this method
to let site visitors download files that aren't publicly accessible.

The method doesn't check whether the file appears in a specific document. Any file of the site can be
retrieved by its ID, so control which file IDs you expose to site visitors in your app.

If the file doesn't exist, the method fails with a `MEDIA_RESOURCE_NOT_FOUND` error.

---

## REST API

### Schema

```
 Method: generateFileDownloadUrl
 Description: Generates a temporary URL for downloading the file referenced by a file node in a Ricos document.  Specify the file node's `fileData.src.id` as `fileId`. The returned URL downloads the original file as an attachment and expires after 10 hours. Private files are supported, so you can use this method to let site visitors download files that aren't publicly accessible.  The method doesn't check whether the file appears in a specific document. Any file of the site can be retrieved by its GUID, so control which file GUIDs you expose to site visitors in your app.  If the file doesn't exist, the method fails with a `MEDIA_RESOURCE_NOT_FOUND` error.
 URL: https://www.wixapis.com/ricos/v1/ricos-document/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: fileId | type: fileId | description: GUID of the file, as specified in the file node's `fileData.src.id`.  Can include a path prefix. For example, `ugd/1a2b3c_4d5e6f.pdf` and `1a2b3c_4d5e6f.pdf` refer to the same file. | required: true | validation: maxLength 1000
 Return type: GenerateFileDownloadUrlResponse
  - name: downloadUrls | type: array<FileDownloadUrl> | description: Download URLs for the file.  Contains a single URL for the original file.  | validation: maxItems 100
     - name: url | type: string | description: Temporary URL that downloads the file as an attachment. Expires after 10 hours.  | validation: format WEB_URL
     - name: assetKey | type: string | description: Key of the file asset the URL downloads. `src` is the original file.  | validation: maxLength 100

 Possible Errors:
   HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: MEDIA_RESOURCE_NOT_FOUND | Description: Couldn't find the file.


```

### Examples

### Generate a download URL for a file in a Ricos document
```curl
curl -X POST \
'https://www.wixapis.com/ricos/v1/ricos-document/generate-file-download-url' \
-H 'Authorization: <AUTH>' \
-H 'Content-Type: application/json' \
-d '{
  "fileId": "ugd/1b868b_9a6179abb4e84c1c9cd56b01c9cd6194.pdf"
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.richContent.ricosDocuments.generateFileDownloadUrl(fileId)
 Description: Generates a temporary URL for downloading the file referenced by a file node in a Ricos document.  Specify the file node's `fileData.src.id` as `fileId`. The returned URL downloads the original file as an attachment and expires after 10 hours. Private files are supported, so you can use this method to let site visitors download files that aren't publicly accessible.  The method doesn't check whether the file appears in a specific document. Any file of the site can be retrieved by its GUID, so control which file GUIDs you expose to site visitors in your app.  If the file doesn't exist, the method fails with a `MEDIA_RESOURCE_NOT_FOUND` error.
 # 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: GUID of the file, as specified in the file node's `fileData.src.id`.  Can include a path prefix. For example, `ugd/1a2b3c_4d5e6f.pdf` and `1a2b3c_4d5e6f.pdf` refer to the same file. | required: true | validation: maxLength 1000
 Return type: PROMISE<GenerateFileDownloadUrlResponse>
  - name: downloadUrls | type: array<FileDownloadUrl> | description: Download URLs for the file.  Contains a single URL for the original file.  | validation: maxItems 100
     - name: url | type: string | description: Temporary URL that downloads the file as an attachment. Expires after 10 hours.  | validation: format WEB_URL
     - name: assetKey | type: string | description: Key of the file asset the URL downloads. `src` is the original file.  | validation: maxLength 100

 Possible Errors:
   HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: MEDIA_RESOURCE_NOT_FOUND | Description: Couldn't find the file.


```

### Examples

### Generate a download URL for a file in a Ricos document
```javascript
import { ricosDocuments } from "@wix/rich-content";

async function generateFileDownloadUrl() {
  const response = await ricosDocuments.generateFileDownloadUrl("ugd/1b868b_9a6179abb4e84c1c9cd56b01c9cd6194.pdf");
}

/* Promise resolves to:
 * {
 *   "downloadUrls": [
 *     {
 *       "url": "https://download-files.wixmp.com/ugd/1b868b_9a6179abb4e84c1c9cd56b01c9cd6194.pdf?token=<DOWNLOAD_TOKEN>",
 *       "assetKey": "src"
 *     }
 *   ]
 * }
 */

```

### generateFileDownloadUrl (self-hosted)
Self-hosted 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 { ricosDocuments } from '@wix/rich-content';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

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


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

---