I'd like to generate a zip file and download it, however it doesn't look like the utils.downloadFile
method correctly handles a Blob
as an input. I cannot convert it to a string, as the resulting output is no longer a valid .zip file and cannot be opened. Is it possible to get support for blobs in utils.downloadFile
?
2 Likes
Thank you for flagging this! Looks like this is a bug. We reproduced this on our end and added you to the bug ticket so we can keep you updated as a fix is merged
1 Like
Wicked, thanks Grace.
Hi, has this bug been fixed?
Any update please Grace?
Hey all — I just wanted to give an update here, generally it seems like this is a more general issue with how blobs are handled in Retool. One potential workaround is to try the following in a JS query:
function urlContentToBase64(url){
return fetch(url)
.then( response => response.blob() )
.then( blob => new Promise( callback =>{
let reader = new FileReader() ;
reader.onload = function(){ callback(this.result.split(',').pop()) } ;
reader.readAsDataURL(blob) ;
}) ) ;
}
//Usage example using await:
let data = await urlContentToBase64("https://file-examples-com.github.io/uploads/2017/02/zip_2MB.zip") ;
utils.downloadFile({base64Binary: data}, "test", "zip")
1 Like