URL link for attachment field preview

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

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.

5 Likes

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
        )
    )
)
2 Likes

I have created a small script which allows to generate the airtable formula to get multiple url links:

1 Like

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.

Gracias por la formula para extratar las enlances de archivos !!!
Me ahorra mucho tiempo de generar presentacion con muchas fotos.

Saludos

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

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.

1 Like

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

@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, "(?:.* \\()(.*)(?:\\))")
1 Like

Amazing! thank you so much @Justin_Barrett . tried to use this website to generate the regex code but it was very different from your formula, even if I selected only the URL.
I will invest a little more time on it. Of course if you have any advice, I am all ears!

Thanks again,
Matteo

I do all of my testing on regex101.com. Make sure to select Golang in the “Flavor” section in the upper left to ensure the best compatibility with what Airtable uses behind the scenes. Similar to formulas, regular expressions take time, practice, and study to learn. I’m no master by any stretch, but they’re fun to play with. :slight_smile:

1 Like

Thank you so much. I will try to find the time to study regular expressions. They look fun and applicable to several kind of needs in Airtable. Grazie, Matteo