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 20, 2017 03:53 PM
I was trying to find a way to get multiple links and I didn’t find a clean one. Instead of this, If your images have the same number of letter, like when come from a camera “IMG_2000.jpg” and regarding that airtable use a specific number of character to generate the URL’s, then you can do this:
MID( string, Start From Numbers Of Characters of the Name , Number of characters that airtable use )
MID( string, (total characters till comma + Start From Numbers Of Characters of the Name) , Number of characters that airtable use )
…
MID( {img-general}, 15, 57)
& “,” &
MID( {img-general}, (73+15), 57)
& “,” &
MID( {img-general}, (73+73+15), 57)
& “,” &
MID( {img-general}, (73+73+73+15 ), 57)
Hope it’ll be useful to somebody.
If somebody knows a better way, let me know!
Oct 27, 2018 12:43 AM
Awesome. Thanks for posting this
Aug 08, 2020 03:39 AM
This extension allows you to extract every attachment’s URL even if you have multiple in a field.
Aug 14, 2020 11:41 AM
I’ve created a script in order to achieve this for multiple images too.
Aug 17, 2020 02:59 AM
Nov 05, 2020 03:28 AM
For future reference, here’s a version in case filenames contain parentheses or commas for example.
It uses the last couple of characters (usually the extension) from the filename (and URL encodes them in case there are non-safe characters in the name). It also starts searching from the beginning of the URL.
It’s one ugly @#%&$ but pretty reliable…
MID({Image},FIND("(https",{Image})+1,(FIND(ENCODE_URL_COMPONENT(RIGHT(LEFT({Image},FIND('(https://', {Image})-2),4))&')',{Image})+LEN(ENCODE_URL_COMPONENT(RIGHT(LEFT({Image}, FIND('(https://', {Image})-2),4)))-1)-(FIND("(https",{Image},FIND("(https",{Image}))))
Nov 07, 2020 03:33 PM
This worked like magic!! :raised_hands:
However, in my {Image} field, I have several images.
@Tuur, or @W_Vann_Hall - How can I tweak your formula to grab the URL for each image and separate them by a comma? (no spaces… just URL,URL,URL
etc.)
I want to have a formula field that looks at my original image (attachment) field and grabs only the URL for each image/attachment, and have them comma separated.
…or if it’s easier to delimit or separate the different URLS with pipe | or some other delimitter, I’m okay with that too!
Nov 07, 2020 11:48 PM
Have a look at: Formula to get image attachment url
You’ll need to combine my version with that solution… :slightly_smiling_face:
Nov 15, 2020 03:53 AM
Thanks for the reference @Tuur!
I can’t seem to figure out how to adjust the formula to get it to work for my fields where I have several images because the amount of raw/expanded text is not consistent. :disappointed:
I wonder if @Justin_Barrett could help me synthesize his advice in that thread and apply it here.
This formula gives me the first image URL with no problem. I just need to be able to tweak it so there’s a comma and it searches again, for the next image… until there’s no more!
MID({Product_Images},FIND("(https",{Product_Images})+1,(FIND(ENCODE_URL_COMPONENT(RIGHT(LEFT({Product_Images},FIND('(https://', {Product_Images})-2),4))&')',{Product_Images})+LEN(ENCODE_URL_COMPONENT(RIGHT(LEFT({Product_Images}, FIND('(https://', {Product_Images})-2),4)))-1)-(FIND("(https",{Product_Images},FIND("(https",{Product_Images}))))