Help

Airtable Script extension download a file

692 4
cancel
Showing results for 
Search instead for 
Did you mean: 
balazs_farsang
4 - Data Explorer
4 - Data Explorer

Hi!

I am working on a small script thats generate a XLSX file from an airtable base.
I stucked at when I want to download a file. Is there any solution to download from the extension section and not from an attachment field?

Thank you for any help!

4 Replies 4
Saravanan_009
8 - Airtable Astronomer
8 - Airtable Astronomer

Using Airtable Scripting Block

If you are using the scripting block in Airtable, you can create a downloadable link for your generated file. Here’s an example of how you can do this using Javascript:

  1. Generate the File: Use a library like xlsx to create the XLSX file content.
  2. Create a Download Link: Use JavaScript to create a download link for the file.
Saravanan_009
8 - Airtable Astronomer
8 - Airtable Astronomer

Here is a basic example:

// Load the required library (e.g., xlsx)
const XLSX = require('xlsx');

// Create a new workbook and worksheet
const workbook = XLSX.utils.book_new();
const worksheet = XLSX.utils.json_to_sheet([
{ Name: 'John Doe', Age: 30 },
{ Name: 'Jane Smith', Age: 25 }
]);

XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');

// Convert the workbook to binary
const wbout = XLSX.write(workbook, { bookType: 'xlsx', type: 'binary' });

// Convert binary string to an ArrayBuffer
function s2ab(s) {
const buf = new ArrayBuffer(s.length);
const view = new Uint8Array(buf);
for (let i = 0; i < s.length; i++) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
}

// Create a blob from the ArrayBuffer
const blob = new Blob([s2ab(wbout)], { type: 'application/octet-stream' });

// Create a link element
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'example.xlsx'; // Name of the file to be downloaded

// Append the link to the document
document.body.appendChild(link);

// Programmatically click the link to trigger the download
link.click();

// Remove the link from the document
document.body.removeChild(link);
Saravanan_009
8 - Airtable Astronomer
8 - Airtable Astronomer

Using External Hosting

If you are looking to host the file externally and provide a download link in Airtable:

  1. Upload the File: After generating the file, upload it to an external file hosting service (e.g., AWS S3, Dropbox, or a web server).
  2. Generate the Download URL: Obtain the URL for the hosted file.
  3. Include the URL in Airtable: Use the URL in Airtable to provide a link for users to download the file.

Using Airtable Extensions

If you want to leverage Airtable’s built-in extensions (like the Page Designer or others):

  1. Use the Extension: Some extensions might allow you to create a downloadable link or button to download the generated file.
  2. Custom Button: Create a custom button field that triggers a script or URL to download the file.

Hello @balazs_farsang 
This is not possible to directly generate Excel or any downloadable file using an Airtable Script extension.
You can just manually download it as csv using visual UI. OR you can push data to another platform using API and automation. See this for download as CSV https://community.airtable.com/t5/development-apis/how-to-export-table-into-mysql-table-file-or-csv/...

The suggestions from @Saravanan_009 are directly from AI(GPT, or other) responses. Airtable scripts are not allowed to import any external modules. https://chatgpt.com/share/2af8ce7b-6451-47b7-805f-cda61dcf0393
The last response is also not work. Just gives you an error at the end.
A possible solution is just to download it as csv using different views and filters OR create a script that just shows data in a comma-separated or a Table.
@Saravanan_009 It's good to use AI response please cross-check it first.