URL link for attachment field preview

#1

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

#2

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.

2 Likes
#3

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
        )
    )
)
1 Like