A better Internet starts with privacy and freedom.
As the expert in security, we are committed to researching cutting-edge security technologies to protect your digital world.
It is highly recommended that you download our apps now.
Configure CORS (Cross-Origin Resource Sharing) in your Azure Storage account to allow your Angular app's domain. typescript
Append the token to your blob URL: https://[account].blob.core.windows.net/[container]/[filename]?[sas-token] . Use a hidden anchor tag in Angular to trigger the download: typescript
For more control, you can use the official Azure Storage Blob client library for JavaScript. Install the SDK: npm install @azure/storage-blob .
import { BlobServiceClient } from '@azure/storage-blob'; async downloadBlob(containerName: string, blobName: string, sasToken: string) { const blobServiceClient = new BlobServiceClient(`https://[account].blob.core.windows.net?${sasToken}`); const containerClient = blobServiceClient.getContainerClient(containerName); const blobClient = containerClient.getBlobClient(blobName); const downloadResponse = await blobClient.download(); const blob = await downloadResponse.blobBody; // Use a utility to save the blob as a file const url = window.URL.createObjectURL(blob!); const a = document.createElement('a'); a.href = url; a.download = blobName; a.click(); } Use code with caution. 3. Proxying Through a Backend (Secure Method)
The simplest way to download a file without exposing your storage account key is to use a SAS token . This provides time-limited access to a specific file. Generate a SAS token from your backend or the Azure Portal.
Downloading files from Azure Blob Storage in an Angular application can be handled through several methods, depending on whether you want to use the official Azure SDK, a backend proxy, or direct SAS (Shared Access Signature) links. 1. Direct Download via Shared Access Signature (SAS)
downloadFile(url: string, fileName: string) { const link = document.createElement('a'); link.href = url; link.download = fileName; link.click(); } Use code with caution. 2. Using the @azure/storage-blob SDK
If you don't want to handle SAS tokens on the frontend, your Angular app can call a backend API (like ASP.NET Core or Node.js) that fetches the stream from Azure and pipes it to the client.
Copyright © 2023-2024 Secure Signal Inc.