Please do not mark this as a duplicate of similar questions as it is not. This one specifically about downloading CORS protected files ( which is possible ) rather than calling get API ( which is often not)
I need to download some data from S3, that has no CORS settings, to the local harddrive. While one cannot make http requests to such objects the browser still downloads it even though preflight request fails. That is because the link content is not presented to javascript but downloaded directly. That would work for me but... I just need a chunk of a large s3 resource. For some unknown to me reason the way to specify it is to add Range header in the request ( which is a major pain in the rear) You cannot use get request as the preflight request is rejected and you cannot use a simple link as you cannot add a header to it, I tried to use 'no-cors' mode in fetch and it starts downloading the file even creates it locally but it fails to bring any content as the response is opaque. Any way to solve this ?
downloadFile(file: string, url: string, range: string) {
return fetch(
url,
{
headers: {
'Range': range
},
method: 'GET',
mode: 'no-cors',
}
)
.then(response =>
{
return response.blob()
})
.then( blob => {
let g = blob.size//this is always zero
saveAs(blob, file+'.tar') // the files is created but has zero length
}
);
}
'''