Hi,
I'm seeing strange behavior in utils.downloadFile
that I can't figure out. In certain circumstances, the call seems to not trigger the download.
function blobToBase64(blob) {
return new Promise((resolve, _) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.readAsDataURL(blob);
});
}
const urlToDownload = table1.selectedRow.data.audioUrl;
console.log(`Downloading ${urlToDownload}`);
const resp = await fetch(urlToDownload);
const bytes = await resp.blob();
console.log(bytes.size); // this returns 481070, so lots of data
const base64Data = await blobToBase64(bytes);
const fileData = {base64Binary: base64Data};
console.log(typeof base64Data);
console.log(base64Data.slice(0,30)); // data:audio/mpeg;base64,//uQBAA
// console.log(fileData); // this returns an object w/ a loooong base64 string
utils.downloadFile(fileData, table1.selectedRow.data.title, 'mp3');
I'm confident this code generates a base64 string correctly. E.g. the string in base64Data
begins with data:audio/mpeg;base64,//uQBAA....
and the base64Binary
key in the object into downloadFile is from the docs.
When I make that call, the query finishes successfully but no file is downloaded.
However, when I make fileData
something trivial, like the string "abcdef"
, the file is downloaded.
Wondering if you could help troubleshoot. Thank you!