Help

Re: How can I open a PDF attachment in my web browser rather than in Airtable's viewer?

Solved
Jump to Solution
3476 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Jonathan_Goldma
5 - Automation Enthusiast
5 - Automation Enthusiast

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. 

1 Solution

Accepted Solutions
Jonathan_Goldma
5 - Automation Enthusiast
5 - Automation Enthusiast

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".

See Solution in Thread

5 Replies 5
Lom_Labs
7 - App Architect
7 - App Architect

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.

Get URL.gif

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
});

 

ScottWorld
18 - Pluto
18 - Pluto

@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.)

Yes, thanks @Lom_Labs! I will try this method.

@ScottWorld, how would you do this with an automation?

@Jonathan_Goldma 

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! 😎

Jonathan_Goldma
5 - Automation Enthusiast
5 - Automation Enthusiast

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".