Help

Extract the first image/attachment to upload it in another column

Topic Labels: Automations
Solved
Jump to Solution
2768 7
cancel
Showing results for 
Search instead for 
Did you mean: 
Tony
5 - Automation Enthusiast
5 - Automation Enthusiast

Hello, 

We are struggling to extract the first image of a column called "photos" then re-upload it in another column. 
We tried to do it by having a formula to extract the first attachment url (which is working) :

 

(IF(BLANK(photos), "", MID(photos, FIND("(", photos) + 1, (FIND(")", photos) - 1) - (FIND("(", photos))))

 


Then, using the following automation to upload it in our target column "1st_photo" :
=> WHEN a record match conditions "photos" isn't empty THEN update the column "1st_photo" using the url from the formula column as input. However, this automation isn't working

I guess the issue come from the attachment url. Do you have any idea to handle it ? 
Does it require a script ? 

Thank you very much !

 
2 Solutions

Accepted Solutions
Sho
11 - Venus
11 - Venus

This can be done in one automation.

First add a single line text field that records the list of download URLs from the automation.
Then add the following formula field that extracts the first URL from the list of download URLs

REGEX_EXTRACT({Download URLs},"(^[^, ]*)((, )|$)?")

In the Automation settings
1. Trigger when the attachment is updated
2. Update the download URL list
3. Delay script 1 second (as it sometimes fails without delay)

function delay(ms) {
var limit = new Date();
limit = limit.setMilliseconds(limit.getMilliseconds() + ms);
while ((new Date()) < limit) {
    // do nothing
    ;
}

delay(1000); //delay 1 second

*This script is shared by this community

4. Upload with extracted URLs

This is updated even if the first attachment is changed by manual sorting.

See Solution in Thread

Tony
5 - Automation Enthusiast
5 - Automation Enthusiast

Thank you for your advices @Sho  ! 

I followed the steps but it was too buggy, even when I was using the delay script set to 3 secondes the automation was very unstable and the 1st photo wasn't uploaded in many cases. 

I found another easy way to handle it through an easy Make automation.

Capture d’écran 2023-09-19 à 23.10.48.png

1 - Search for record (not having the 1st picture uploaded in your target column). You can create a view on Airtable to filter only the record you want to update.


2 - Update the record by mapping the attachement fields (array)'s first element into your target column.

Capture d’écran 2023-09-19 à 23.12.06.png



 

See Solution in Thread

7 Replies 7
Sho
11 - Venus
11 - Venus

Hello @Tony,

Unfortunately, URL for the attachment field that can currently be referenced in the formula is an invalid URL.

However, various URLs and other values can be retrieved from automation.

2023-09-19 092247.png

"Expiring Download URL" can be used to upload to other Attachment fields.

Tony
5 - Automation Enthusiast
5 - Automation Enthusiast

Thank you for the reply @Sho.

So if we want to extract the first attachment. I guess the only solution would be to run a sript or an automatisation with Make ?

 
Sho
11 - Venus
11 - Venus

This can be done in one automation.

First add a single line text field that records the list of download URLs from the automation.
Then add the following formula field that extracts the first URL from the list of download URLs

REGEX_EXTRACT({Download URLs},"(^[^, ]*)((, )|$)?")

In the Automation settings
1. Trigger when the attachment is updated
2. Update the download URL list
3. Delay script 1 second (as it sometimes fails without delay)

function delay(ms) {
var limit = new Date();
limit = limit.setMilliseconds(limit.getMilliseconds() + ms);
while ((new Date()) < limit) {
    // do nothing
    ;
}

delay(1000); //delay 1 second

*This script is shared by this community

4. Upload with extracted URLs

This is updated even if the first attachment is changed by manual sorting.

Tony
5 - Automation Enthusiast
5 - Automation Enthusiast

Thank you for your advices @Sho  ! 

I followed the steps but it was too buggy, even when I was using the delay script set to 3 secondes the automation was very unstable and the 1st photo wasn't uploaded in many cases. 

I found another easy way to handle it through an easy Make automation.

Capture d’écran 2023-09-19 à 23.10.48.png

1 - Search for record (not having the 1st picture uploaded in your target column). You can create a view on Airtable to filter only the record you want to update.


2 - Update the record by mapping the attachement fields (array)'s first element into your target column.

Capture d’écran 2023-09-19 à 23.12.06.png



 

Sho
11 - Venus
11 - Venus

Was it no work?
I had no problem testing with light images. It seems to fail if the upload takes too long.
If it fails in one automation, it might be better to split it into two.
Anyway, MAKE would be a sure thing.

Fazia_Fayyaz
5 - Automation Enthusiast
5 - Automation Enthusiast

hello @Sho how to extract first image from multiple image attachments in airtable in same table I want only 1st pic shown in the column from multiple image attachements 

 

Sho
11 - Venus
11 - Venus

Hello @Fazia_Fayyaz,

One automation was unstable, so two should be fine.

In addition to the Attachment field, add the following four additional fields
"Attachment IDs" single-line string field
"Attachment URLs" single-line string field
"First Attachment ID" formula field with the formula

REGEX_EXTRACT({Attachment IDs},"(^[^, ]*)((, )|$)?")

"First Attachment URL" formula field, with the formula

REGEX_EXTRACT({Attachment URLs},"(^[^, ]*)((, )|$)?")

 

The two automations are set up as follows

Automation1 Setting
It will be trigger each time the Attachment field is updated.Attachment Automation1.png

How to get Attachment's ID and URL is to change Display properties.DisplaySetting.png

Automation2 Setting
Automation2 is triggered only when the First Attachment ID is changed.Attachment Automation2.png

Give it a try.