> 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: 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 | description: Keys for downloading different assets (format and quality) of a file. Default: `src`, key representing the original file's format and quality. 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.
**Note:** The name that appears in the Media Manager is taken from the `filename` parameter in the Generate File Upload Url call. param name: expirationInMinutes | type: expirationInMinutes | description: The time that it takes in minutes for the download URL to expire.
Default: `600`.
Limit: `525600` (1 year). param name: expirationRedirectUrl | type: expirationRedirectUrl | description: The redirect URL for when the temporary download URL with a token expires.
Default: A 403 Forbidden response page. 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 Return type: GenerateFileDownloadUrlResponse - name: downloadUrls | type: array | description: URL for downloading a specific file in the Media Manager. - name: url | type: string | description: The file download 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. 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: ' -H 'Content-Type: application/json' \ --data-binary '{ "fileId": "4acbb8_7596aeebcf5c41eca01c0d99667ac967.mp3", "downloadFileName": "Gorillaz - Feel Good Inc.mp3", "expirationInMinutes": "60", "expirationRedirectUrl":"www.mysite.com/store", "assetKeys": ["320kbs.mp3"] }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.mediaManager.FilesService.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 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.
**Note:** The name that appears in the Media Manager is taken from the `filename` parameter in the Generate File Upload Url call. - name: expirationInMinutes | type: integer | description: The time that it takes in minutes for the download URL to expire.
Default: `600`.
Limit: `525600` (1 year). - name: expirationRedirectUrl | type: string | description: The redirect URL for when the temporary download URL with a token expires.
Default: A 403 Forbidden response page. - name: assetKeys | type: array | description: Keys for downloading different assets (format and quality) of a file. Default: `src`, key representing the original file's format and quality. - 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 - name: downloadUrls | type: array | description: URL for downloading a specific file in the Media Manager. - name: url | type: string | description: The file download 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. 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-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 { 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); }; ``` ---