Trying to use theslate.downloadBlobfunctionality
I have this code attached to a button::onClick, (it is just creating a hello world text file) from the documentation. but no file download is triggered.
// Debug log: selected row keys (paths)
console.log("Selected row keys (paths):", {{w_table_1.selectedRowKeys}});
const selectedRowKeys = {{w_table_1.selectedRowKeys}};
const tableData = {{w_table_1.data}};
const EW_RAW_FILES_RID = "ri.foundry.main.dataset2d371154-548e-4b6f-b20c-44a1cf650928";
if (selectedRowKeys.length > 0) {
const fileName = selectedRowKeys[0];
// Debug log: file to be downloaded
console.log("Downloading file:", fileName);
try {
var theQuery = {{q_query_1}};
console.log("File downloaded successfully:", fileName);
console.log("Query result:", theQuery.result);
console.log("Query result:", theQuery.result[0]);
// Handle different result formats
let fileData;
//let mimeType = "application/octet-stream"; // Default for binary files
let mimeType = "application/pdf"; // Default for binary files
if (theQuery.result && theQuery.result.length > 0) {
fileData = theQuery.result[0];
// If it's a string (base64), convert it
if (typeof fileData === 'string') {
// Assuming base64 encoded data
const binaryString = atob(fileData);
const bytes = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
fileData = bytes;
}
} else {
throw new Error("No file data received from query");
}
console.log("Download initiated for:", fileName);
console.log("mimeType:", mimeType);
let theBlob = new Blob(["Hello, world!"], { type: "text/plain;charset=utf-8" })
//new Blob([fileData], { type: mimeType })
console.log("Blob object:", theBlob);
console.log("Blob size:", theBlob.size);
console.log("Blob type:", theBlob.type);
//return {
// fileName: "yo.pdf",
// blob: theBlob
//};
return {
fileName: "my_file.txt",
blob: theBlob
};
} catch (error) {
console.error("Error downloading file:", error);
return null;
}
}
// Debug log: no rows selected
console.log("No rows selected for download.");
return null;