Skip to main content
Solved

Extract most recent attachment URL from list of attachments

  • July 20, 2023
  • 3 replies
  • 69 views

Forum|alt.badge.img+4

I have a formula field that returns the URLs of an attachment field. If there's only one attachment, it returns one URL in parentheses. But multiple attachments take this form: "File Name 1 (URL 1), File Name 2 (URL 2)".

Here is an example: "Screenshot 2023-07-03 141051.png (https://dl.airtable.com/.attachments/c53420d1c5692651db4f6c34e5ddc19f/8256aa0b/Screenshot2023-07-03141051.png), Screenshot 2023-06-23 130019.png (https://dl.airtable.com/.attachments/1d08cfcdd7ce28fa575f0c20738ae2ea/bc5c5421/Screenshot2023-06-23130019.png)".

I want to write a formula that will extract only the URL in the last set of parentheses, no matter how many other files are listed in the cell (or just the single URL if there's only one file). In other words, I want to extract the URL of the most recently uploaded attachment, which is always the last one listed in the cell.

Best answer by ScottWorld

Unfortunately, formulas no longer return valid URLs, so you won’t be able to use formulas to grab valid URLs for attachment fields.

However, you can use automations to grab URLs of the attachments. Note that those URLs are now “expiring URLs”, and they will expire 2 hours after a non-Airtable user accesses that URL for the first time.

You can either use Airtable’s native automations to grab those expiring URLs, or you can use Make’s advanced Airtable automations to do the same thing.

Also, if you need the URLs to last longer than 2 hours, then you will want to store your attachments on a cloud storage space like Google Drive. You can automatically do that with Make as well. I describe that process in this thread: Archiving Attachments in Google Drive.

Hope this helps!

If you’d like to hire the best Airtable consultant to help you with anything Airtable-related, please feel free to contact me through my website: Airtable consultant — ScottWorld

3 replies

ScottWorld
Forum|alt.badge.img+35
  • Genius
  • Answer
  • July 20, 2023

Unfortunately, formulas no longer return valid URLs, so you won’t be able to use formulas to grab valid URLs for attachment fields.

However, you can use automations to grab URLs of the attachments. Note that those URLs are now “expiring URLs”, and they will expire 2 hours after a non-Airtable user accesses that URL for the first time.

You can either use Airtable’s native automations to grab those expiring URLs, or you can use Make’s advanced Airtable automations to do the same thing.

Also, if you need the URLs to last longer than 2 hours, then you will want to store your attachments on a cloud storage space like Google Drive. You can automatically do that with Make as well. I describe that process in this thread: Archiving Attachments in Google Drive.

Hope this helps!

If you’d like to hire the best Airtable consultant to help you with anything Airtable-related, please feel free to contact me through my website: Airtable consultant — ScottWorld


Forum|alt.badge.img+21
  • Inspiring
  • July 21, 2023

This is possible by using automation to return a list of viewer URLs for attachments.

Create a Single Line Text field to receive the URL list string, and use automation to update the URL when the attachment is updated.
In the Open URL expression of the Formula field or button,

REGEX_EXTRACT({URL},".*, (.*)$")

Only the last URL is extracted.


Irit_Levi
Forum|alt.badge.img+6
  • Participating Frequently
  • April 24, 2025

Use this script to extract multiple attachment URLs.

In this case Invoices is where the attachments are and Invoice URLs is a long text field to capture the URLs.

 

// Get input variables from the automation

let inputConfig = input.config();

let recordId = inputConfig.recordId;

 

// Load the record from the Orders table

let table = base.getTable("Orders");

let record = await table.selectRecordAsync(recordId);

 

let attachments = record.getCellValue("Invoices") || [];

 

let urls = attachments

  .map(file => file.url)

  .join("\n");

 

// Update the record with the extracted URLs

await table.updateRecordAsync(recordId, {

  "Invoice URLs": urls

});

 

 

Just make sure to create an input variable called recordId with the Record ID.