I’m using a Coda webhook to upload data to a table and I would like to have a column of attachments. It would be a file type column with 0 or more files per row. It doesn’t look like I can use the webhook to upload files directly, so I’m trying to base64 encode the files and upload them to a text column. I would like to have a formula column that parses the base64 strings to actual attachments when a new row is created. I got it working for images via custom pack formula using this approach: Working with images and files - Coda Pack SDK, but I can’t get it working for other file types. I read somewhere in the Coda docs that attachments can only be displayed in a sync table for now, but I wanted to check if there are any better solutions to this.
Update:
I’m able to return the tmp storage url for a single file using this code, although it doesn’t create a native file attachment:
pack.addFormula({
name: “parse_base64_attachments”,
description: “Convert a list of base64 encoded files to native attachments”,
parameters: [
coda.makeParameter({
type: coda.ParameterType.StringArray,
name: “b64_str”,
description: “Data string”
}),
coda.makeParameter({
type: coda.ParameterType.StringArray,
name: “file_type”,
description: “File type”
})
],
resultType: coda.ValueType.Array,
items: { type: coda.ValueType.String },
execute: async function ([b64_str, file_type], context) {
const result = [] as string[];
for (let i = 0; i < b64_str.length; i++) {
let buffer = Buffer.from(b64_str[i], "base64");
let tmp_data_url = await context.temporaryBlobStorage.storeBlob(buffer, file_type[i]);
result.push(tmp_data_url)
}
return result;
},
});
When I try to a pass a list of base64 strings and a list of file types, I get an internal error:
Please keep updating - really interested in this solution if you find one
Update:
By passing the base64 strings and the file type strings as lists, I’m able to return a list of the temp storage urls, but it’s still not converting to native attachments.
Update:
I got it working for images by changing the pack formula to have result type array with items of string and value type attachment:
resultType: coda.ValueType.Array,
items: {
type: coda.ValueType.String,
codaType: coda.ValueHintType.Attachment
},
It’s not working for other types of attachments (pdf or docx) yet. For those I get this instead of the file:
Coda will only ingest files and create attachments if this comes through a Sync Table:
So if you need those to actually be stored as attachments, one workaround would be:
-
The webhook takes the data and stores it to a cell in some temporary table
-
The pack exposes a Sync Table that’s set up to read from that table:
- either the temporary table has a specific hard-coded name and the pack locates it by name,
- or the sync table is a dynamic sync table where you can either select or insert the URL of that temporary table with the data
- or you can pass the data through a parameter — but I think this may fail because there could be size limits on parameters and the data may not fit these.
-
The sync table will read the base64 upload, make a file out of it, put to temporary blob storage, and then return it within a sync table as FileAttachment.
Thanks @Paul_Danyliuk for the guidance. I’m not too familiar with sync tables. Can you point me to the docs for how to use an existing table as a source for a sync table?
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.