May 04, 2019 06:18 PM
I have some PDF files in an Attachment field. I need to generate URL links to the airtable preview of these attachments. I know it can be done (the URL links appear with as dl(dot)airtable(dot)com/.attachments/). How do I generate these URL’s
May 04, 2019 06:41 PM
For a bare-bones approach, just put the name of your Attachment field into a formula by itself. Airtable will display the name of the document, followed by the URL in parentheses.
If you want only the URL, use this, replacing {Field Name}
with your own Attachment field name:
REPLACE(
LEFT(
{Field Name},
LEN(
{Field Name}
) - 1
),
1,
FIND(
"(",
{Field Name}
),
""
)
Note that this formula will only work if there’s a single file in the Attachment field. It’s not “smart” enough to strip the extra content for multiple attachments.
May 05, 2019 07:54 AM
Just thought I’d throw this in as well! I ran across a situation where I wanted to grab a field’s “Primary Photo”, i.e. the first image when a field has multiple attachments. The output of the attachment array is in reverse order, so the following formula grabs the last URL for a field with multiple attachments, or the first/only URL in a field with just one attachment. Unfortunately, it still only grabs one URL.
Side note: You could use Zapier to get all of the URLs for a particular field. For example if you want to attach all of them to an email, Zapier automatically strips out the file name and what not and gives you just the URLs to use. Or if you need to use each one separately, there’s a Formatting step that can split the URLs into separate fields.
Anyway, here’s the formula!
IF(
AND(
{Pictures},
FIND(
",",
{Pictures}
) = 0
),
RIGHT(
LEFT(
{Pictures},
LEN(
{Pictures}
) - 1
),
LEN(
LEFT(
{Pictures},
LEN(
{Pictures}
) - 1
)
)
- SEARCH(
"https://",
{Pictures}
) + 1
),
IF(
{Pictures},
RIGHT(
LEFT(
RIGHT(
{Pictures},
FIND(
",",
{Pictures}
) - 1
),
LEN(
RIGHT(
{Pictures},
FIND(
",",
{Pictures}
) - 1
)
) - 1
),
LEN(
LEFT(
RIGHT(
{Pictures},
FIND(
",",
{Pictures}
) - 1
),
LEN(
RIGHT(
{Pictures},
FIND(
",",
{Pictures}
) - 1
)
) - 1
)
)
- SEARCH(
"https://",
RIGHT(
{Pictures},
FIND(
",",
{Pictures}
) - 1
)
) + 1
)
)
)
Aug 14, 2020 09:09 AM
I have created a small script which allows to generate the airtable formula to get multiple url links:
Aug 14, 2020 09:28 AM
I think that this tool is your best bet — it works for both single attachments & multiple attachments:
You can also create your own tool like this by using Integromat to iterate through your attachments and extracting their URL’s.
Aug 20, 2020 12:36 AM
Gracias por la formula para extratar las enlances de archivos !!!
Me ahorra mucho tiempo de generar presentacion con muchas fotos.
Saludos
Jun 06, 2021 02:33 PM
Hi @Justin_Barrett. Your formula works great but could you please suggest how should I change it if the attachment name contains some parenthesis?
Example: if the attachment name is FILE(1).pdf, I get 1).pdf(https://dl.airtable.com/.attachments/xxxxxx…)
Thanks,
Matteo
Jun 07, 2021 09:19 AM
There’s a much easier way to do this using the REGEX_EXTRACT()
function:
REGEX_EXTRACT(Field, "(.*)(?: \\(.*)")
That will extract everything up to—but not including—the space and opening parenthesis that mark the beginning of the file URL, which will give you only the filename, even if it also contains a parenthesis.
Jun 08, 2021 09:24 AM
This is great @Justin_Barrett but how do I get the URL only? I tried using REGEX REPLACE to replace what I get with your formula with “” but I obtain a blank cell.
Sorry if I am missing something obvious and thank you for your help
Matteo
Jun 08, 2021 10:19 AM
@Matteo_Ottaviani Your example above indicated that you wanted the filename, so I built the regex to extract the filename. To get the URL, use this:
REGEX_EXTRACT(Field, "(?:.* \\()(.*)(?:\\))")