Apr 18, 2020 04:49 AM
Dear Airtable community,
I have the following use case: inside my Airtable DB I have an image table holding about 9000 records whereas each record has an attachment field (among other fields) holding a single image of a certain resolution. I would now like to (1) download all these images, (2) do some optimizations on them (using e.g. imagemagick) and (3) re-upload the processed images replacing the previous ones. Steps (1) and (2) I’m confident to figure out myself how to do that. For step (3) however I’m a bit lost. Do you have any suggestions about how to best realize that in a (semi-) automated way? Any scripting fragments or similar would be a great help.
Thanks, Stefan
Apr 18, 2020 05:08 AM
Step 3 is the kicker. The way I’d approach it (just from thinking about it briefly) is either:
Carry out steps 1 & 2. ensuring that the image name is the same and unique across all records, use the API to lookup based on the image name, and replace with new image
Depending on what you need to do with Image Magick you could maybe do the same thing with an image automation platform (e.g Transloadit)
Apr 18, 2020 07:00 AM
Thanks for your reply @andywingrave. Do you happen to have a code snippet showing how to upload an image file to a specific record field replacing the previous one?
Thanks, Stefan
Apr 18, 2020 08:12 AM
I don’t at the moment, sadly :pensive:
Perhaps ask in the Work Offered category for now?
Apr 18, 2020 11:17 AM
Thanks @andywingrave. I think I have found a way to solve that. Using Airtable Scripts Block, the following code snippet can update a record with an image, provided the image can be read from a remote server:
let newAttachmentUrl = 'https://www.domain.com/mynewimage.jpg';
await table.updateRecordAsync(record, {
"ImageField": [
{ url: newAttachmentUrl,
filename: 'mynewimage.jpg' }
],
})
Regards, Stefan
Apr 18, 2020 11:27 AM
Awesome! Nice one! Thank you for posting the solution!