# Use Blob Objects for Download Links

Lightning Web Security (LWS) blocks the use of `data:` URIs in anchor links because that approach has various security issues. Use a `blob:` URI instead.

This example shows an approach to creating a dynamic plain text file download link that uses a `data:` URI. This approach requires allowing `data:` URIs generally, which is insecure.

```sfdocs-code {"lang":"javascript", "title": "Download link using a data: URI, considered insecure"}
// EXAMPLE OF INSECURE DOWNLOAD LINK
// This technique is prevented by LWS
const textEncoded = `data:text/plain,${encodeURIComponent( 'text string' )}`;
let anchorTag = document.createElement('a');
anchorTag.setAttribute('href', textEncoded);
anchorTag.setAttribute('download', 'nameoffile.crt');
anchorTag.click();
```

Instead, create a `Blob` to hold the data, and use the `blob:` URL scheme to make it available for download.

```sfdocs-code {"lang":"javascript", "title": "Download link using a blob: URI, allowed by LWS"}
const blob = new Blob(['text string'], { type: 'text/plain' });
const blobUrl = URL.createObjectURL(blob);
const anchorTag = document.createElement('a');
anchorTag.setAttribute('href', blobUrl);
anchorTag.setAttribute('download', 'nameoffile.crt');
anchorTag.click();
URL.revokeObjectURL(blobUrl);
```

`data:` URIs embed content directly inline as a URL. This creates several security risks that LWS blocks. A `blob:` URL is bound to the origin that created it — it inherits the page’s origin, and is subject to same-origin policy. This and other attributes make `blob:` a controlled, auditable mechanism for a legitimate use case (file downloads) without the open-ended risks of `data:`.
