Jul 19, 2017 06:07 PM
Admittedly, an edge case, but in working with the Airpress WordPress-to-Airtable API and plugin, I ran into problems when attempting to display only the first image from an attachment field. After hours spent stepping my way through the plugin, I finally discovered I’d been debugging the wrong module entirely. Discouraged, I took a break, fed the cat, got another cup of coffee – and then wondered if I might not be able to goose Airtable into giving me the data directly.
Five minutes later, I had it.
The example assumes an Attachment field named ‘images’, but should work with attachments of any type.
To extract the URL
MID(images,FIND("(",images)+1,(FIND(")",images)-1)-(FIND("(",images)))
To extract the file name
LEFT(images,FIND(" ",images)-1)
This works because Airtable will cast an Attachment field to a comma-delimited string of values when it is acted upon by a text function. Each attachment value consists of two parts, separated by a space: the original file name (sans path) and the Airtable URL, enclosed in parentheses – as so:
FileName1 (URL1),FileName2 (URL2),[...],FileNameX] (URL[x])
Again, probably not of interest for most Airtable users – but if I’d thought about it earlier, I could have saved myself a day’s effort.
Nov 23, 2020 09:54 PM
This looks great @Miquel_Capo_Casasnov!! Curious if additional suffix filenames could be added… e.g. could you have the “End Field” allow .jpg OR .png OR .gif OR .pdf OR .webp etc.
We have a variety of image/file types that we are putting in this field and would like to define an array of possible suffixes.
Nov 24, 2020 01:10 AM
You can simply remove parenthesis from image files. And then use the first script or use the second removing “.jpg” from the end string “.jpg)” to leave it like this “)” so it will take the parenthesis as end string and any format will be working.
Nov 24, 2020 06:41 AM
Yup, that’s the tradeoff that I mentioned for that particular solution. Unless you need to see all of those fields, though, you could just hide them.
The solution from @Miquel_Capo_Casasnov is definitely better if you want a single formula, but its logic puts constraints on how the files are named as he pointed out.
As you’re discovering, virtually any solution to this problem has its pros and cons, including a scripting solution. The big pros with that option are that you wouldn’t need any formula fields, you’re free to edit the final result if needed, and filename formatting wouldn’t matter. The con is that it requires a Pro-plan workspace, which isn’t an option for some.
Feb 12, 2021 08:40 AM
Which is why I came up with a version that doesn’t care about parentheses or commas. :winking_face:
Dec 19, 2021 10:22 AM
Thank you for sharing!
Dec 29, 2021 07:32 AM
We have this as an easy no-code function in our On2Air Actions app