I have the following use case. We are using AWS presigned url which is SSE-C signed. We need to pass the required headers to use and download from the presigned url. I have the below mentioned code which is working. The problem is that for large files, it is erroring out and there is no visal cue for the customer that the download is in progress or not. Is there an easy way to download files for url(which need headers). if the headers wouldnt have been there, I could have simply done window.open to initiate the browser download. Please suggest.
function downloadFile() {
const presignedUrl = 'myurl';
//header
const headers = {
'x-amz-server-side-encryption-customer-algorithm': 'AES256',
'x-amz-server-side-encryption-customer-key': 'abc',
'x-amz-server-side-encryption-customer-key-MD5': 'xyz'
};
// fech with header
fetch(presignedUrl, { headers })
.then(response => {
if (response.ok) {
return response.blob();
} else {
throw new Error('Failed to download file');
}
})
.then(blob => {
// Save the file to local machine
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'file_download';
document.body.appendChild(a);
a.click();
a.remove();
})
.catch(error => {
console.error(error);
});
}