Help

Re: Batch downloading and naming images

410 0
cancel
Showing results for 
Search instead for 
Did you mean: 
dianablanco
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi, Has anyone been able to figure out how to batch download images from Airtable into a folder with a naming protocol for each image based on information from the same row? Thank you, Diana

6 Replies 6
Kenneth_Raghuna
7 - App Architect
7 - App Architect

I have a script that renames images when added to the record using info from the record:

let config = input.config();
let table = base.getTable("Musicians/Presenters");
let query = await table.selectRecordsAsync();
let record = query.getRecord(config.recordID);
let logo_field = table.getField("Logo")
let headshot_field = table.getField("Headshot")

//Collect Record Data
let stage = record.getCellValue("Stage");
let logos = record.getCellValue("Logo");
let headshots = record.getCellValue("Headshot");
let name = record.getCellValue("Performance");

//Function that takes files and field id, renames files
async function renameFiles(files, field) {
    let newfiles = []
    for (let file of files) {
        let parts = file.filename.split(".")
        let ext = parts[parts.length - 1]
        let fileNumber = "0" + (files.indexOf(file) + 1)
        let newName = `${stage}_${field.name}_${name}_${fileNumber}.${ext}`
        newfiles.push({url: file.url, filename: newName})
    }

    //publish changes
    await table.updateRecordAsync(record, {
        [field.name]: newfiles
    })
}

//Run function when data is present
if(logos){
    renameFiles(logos, logo_field);
}

if(headshots){
    renameFiles(headshots, headshot_field);
}

I use the script in an automation that detects when the relevant attachment field gets populated.

To do bulk downloads though, you'll either need to use a paid extension (see miniExtensions), a third party service (like Make or Zapier), or run a script from your computer. There are some examples of shell scripts on the forums, here is a link to one in python on github.

DisraeliGears01
6 - Interface Innovator
6 - Interface Innovator

Kenneth that script is sick.

As you mentioned though, if the focus is moving the AT images into a folder, rather than implementing that script I'd just build the whole thing on Make and integrate re-naming into the process of moving the files.

It all depends on the use case. Renaming within the base offers the ability to ensure that the filenames adhere to the expected naming convention whether they are downloaded in bulk, or one by one from within AT.

If downloading single files is never expected within the work flow, renaming files in Make/Zapier would be a lot more user-friendly than a script.

ScottWorld
18 - Pluto
18 - Pluto

I usually do this with Make’s advanced automations for Airtable.

I would strongly recommend against using Zapier, because Make is INFINITELY more powerful & customizable than Zapier, yet it is SIGNIFICANTLY CHEAPER than Zapier.

I wrote an entire post here comparing Make vs. Zapier: https://air.tableforums.com/t/make-vs-zapier/737 

The downside is that if you’ve never used Make before, it will take you a few hours to learn how to use it, so I’ve assembled a bunch of Make training resources in this thread: https://air.tableforums.com/t/make-com-basic-navigation-tips/277

— ScottWorld, Expert Airtable Consultant

Thank you, Kenneth! This script is fantastic!

Thank you, Scott! 

Has anyone been able to use Make to save all of the renamed images to a Sharepoint folder?