May 10, 2023 11:52 AM
I have an Airtable table that I'm using as a library to organize many documents, most of which are PDFs. The organization features (tagging, categorizing, etc.) are all working great. However, Airtable's PDF viewer is just not nearly as good for me as my preferred open (Adobe's Chrome plugin).
I used to be able to have a button or formula field that would allow me to open each record's attachment in the browser's default app by extracting the attachment's URL. However, I understand that attachment URLs now change frequently for security reasons, so this solution no longer works. How can I open a PDF attachment in my web browser rather than in Airtable's viewer? This seems like something that should be easy. Note that I can download the PDF and open it on my desktop as a second-best solution.
Solved! Go to Solution.
May 13, 2023 06:12 AM
Thanks @ScottWorld . I solved this using your advice. More specifically, I made the following automation:
Trigger: every 2 hours
Action 1: Find all records in the table
Action 2: Repeat for all records found in Action 1; Update record to set the "File Link" text field equal to the "File" attachment field property "Expiring Download URL".
May 11, 2023 02:51 AM
Hello @Jonathan_Goldma!
I've developed a script extension that allows you to retrieve the temporary URL of your attachments! As you have noted, the URLs change frequently for security reasons, so the provided URL will only remain active for 1-2 hours, but this should be more than enough for your needs.
To utilize this, simply set up the extension and select a record. If desired, you can also incorporate a button field for added functionality.
Here is the code you need to add to a 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
});
May 11, 2023 08:59 AM - edited May 11, 2023 09:00 AM
@Jonathan_Goldma Cool solution from @Lom_Labs. You can also do this same thing with an Airtable automation -- no scripting required! (And for more advanced automations, external tools like Make will do this as well.)
May 11, 2023 09:17 AM
Yes, thanks @Lom_Labs! I will try this method.
@ScottWorld, how would you do this with an automation?
May 11, 2023 02:06 PM
Whenever you reference an attachment field in an Airtable automation, Airtable gives you the opportunity to use the expiring URL. So just trigger your automation in any way that you'd like, and then put that expiring URL into another field.
This exact same behavior works the exact same way in Make, so if you have more advanced automations that Airtable can't handle natively on its own, you can use Make to do the exact same thing.
No scripting required for any of this! 😎
May 13, 2023 06:12 AM
Thanks @ScottWorld . I solved this using your advice. More specifically, I made the following automation:
Trigger: every 2 hours
Action 1: Find all records in the table
Action 2: Repeat for all records found in Action 1; Update record to set the "File Link" text field equal to the "File" attachment field property "Expiring Download URL".