// Angular Service example import { HttpClient } from '@angular/common/http'; downloadFromS3(presignedUrl: string) { this.http.get(presignedUrl, { responseType: 'blob' }).subscribe((blob: Blob) => { const url = window.URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = 'filename.ext'; // Explicitly set filename link.click(); window.URL.revokeObjectURL(url); }); } Use code with caution. Method 2: Direct Download via AWS SDK
import * as AWS from 'aws-sdk'; const s3 = new AWS.S3({ accessKeyId: 'YOUR_ACCESS_KEY', secretAccessKey: 'YOUR_SECRET_KEY', region: 'YOUR_REGION' }); downloadFile(bucketName: string, fileKey: string) { const params = { Bucket: bucketName, Key: fileKey }; s3.getObject(params, (err, data) => { if (err) { console.error("Error downloading file:", err); } else { const blob = new Blob([data.Body as Uint8Array]); const url = window.URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = fileKey.split('/').pop(); // Get name from key link.click(); } }); } Use code with caution. Critical Security & Configuration Actually Download File from S3 bucket to local machine download file from s3 bucket angular 8
If your application architecture requires direct interaction from the browser, you can use the aws-sdk package. : npm install aws-sdk --save . // Angular Service example import { HttpClient }
: Your Angular app requests a temporary URL from your backend (e.g., Node.js, Spring Boot, or .NET). : npm install aws-sdk --save