Help

Re: URL link for attachment field preview

4198 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Nathan_Brown
4 - Data Explorer
4 - Data Explorer

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

12 Replies 12

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.

AlliAlosa
10 - Mercury
10 - Mercury

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
        )
    )
)
Miquel_Capo_Cas
6 - Interface Innovator
6 - Interface Innovator

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

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.

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