I have developed a mobile app and as a function when the button is clicked, table data will retrieved and create an HTML file. I need to download this file and share it with others. I have tried many ways and this is the only working code that I'm having. However, in the mobile app (iOS) this file generates without the".html" extension and I have to manually include the same to view the HTML file data. How to fix this.???
===================
Code:
const data = query42.data;
// Check if data exists
if (!data || Object.keys(data).length === 0) {
console.error("No data found for the provided query.");
return;
}
// Transform columnar data to row-based data
const transformedData = ;
const numRows = data[Object.keys(data)[0]].length; // Number of rows (based on the length of the first column)
for (let i = 0; i < numRows; i++) {
const row = {};
for (const key in data) {
row[key] = data[key][i]; // Map each column to the corresponding value for this row
}
transformedData.push(row);
}
// Use the first row as the "record"
const record = transformedData[0];
// Generate HTML for the record
const htmlContent = `
Pre-Inspection Checklist
Vehicle Details
Vehicle Registration | ${record.vehicle_registration || "N/A"} |
---|---|
Make | ${record.vehicle_make || "N/A"} |
Year | ${record.vehicle_year || "N/A"} |
Mileage | ${record.current_mileage || "N/A"} |
Checked By | ${record.checked_by || "N/A"} |
Date | ${record.recorded_date || "N/A"} |
Engine Checklist
Images
</div>
// Encode the HTML content as Base64
const base64Content = btoa(unescape(encodeURIComponent(htmlContent)));
// Use Retool's utils.downloadFile() to trigger the download with proper extension and MIME type
utils.downloadFile(base64Content, "Vehicle_Report.html", "text/html");