May 11, 2023 02:58 AM - edited Mar 05, 2024 05:39 AM
In order to assist a community member in accessing expiring URLs for their attachments, I've developed a new extension! Now, you can effortlessly retrieve the URLs of your attachments with just a click.
Just a heads up, the Airtable makes the URLs expire for security reasons. As a result, the provided URL will only remain active for ~2 hours. Please make a note of this while using the extension.
And here is the code to paste into your script extension!
const settings = input.config({
title: "Get temporary attachment URL",
items: [
input.config.table("table", { label: "Table" }),
input.config.field("attachmentField", { parentTable: "table", label: "Attachments field" }),
input.config.field("temporaryAttachmentURLsField", { parentTable: "table", label: "Field to put URLs" }),
],
});
let { table, attachmentField, temporaryAttachmentURLsField } = settings;
if(attachmentField.type !== "multipleAttachments") {
throw new Error("Attachments field must be an 'Attachments' type field");
}
if(!["singleLineText", "multilineText"].includes(temporaryAttachmentURLsField.type)) {
throw new Error("Field to put URLs must be a single line or long text field");
}
const record = await input.recordAsync("Pick a record", table);
const attachmentsData = record.getCellValue(attachmentField.name);
if(!attachmentsData){
throw new Error("No attachments found for this record");
}
let attachmentURLs = attachmentsData.map(attachment => attachment.url).join("\n\n");
await table.updateRecordAsync(record.id, {
[temporaryAttachmentURLsField.name]: attachmentURLs
});
Sep 24, 2024 09:07 AM
Works great! Thanks for this.