generateUrl

Generates and returns a URL for downloading a file in an LWR site in Experience Cloud.

Syntax 

1import { generateUrl } from "lightning/fileDownload";
2const url = generateUrl(recordId);
3window.open(url);

Parameters 

recordID—(Required) The record ID of the file (ContentDocument, ContentVersion, Attachment, or Document) to be downloaded.

Returns 

A URL for downloading a file.

Usage 

Authenticated users can download files they have access to. Guest users can download only ContentDocument files that they have access to through Library membership.

This code sample generates a URL for downloading a file.

1import { LightningElement, api } from "lwc";
2import { generateUrl } from "lightning/fileDownload";
3
4export default class Download extends LightningElement {
5  @api recordId;
6  url;
7
8  handleClick() {
9    this.url = generateUrl(this.recordId);
10  }
11}