Help

[API] : Rename a picture

856 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Corentin_KELOGH
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi !

I’m trying to rename a picture using the airtable python wrapper (API).
A picture is represented by a list of dict :
Example : {'Picture 1' : [{'id': '...', 'url': '...', 'filename': 'Picture_1.jpeg', 'size': 24150, 'type': 'image/jpeg', ...}]

The problem here is that it’s a list of dict, so you can’t just modify filename. If you want to edit anything in Picture 1, you have to get all properties.

So I obviously tried to airtable_update by copiying properties, then edit filename and airtable_update.
The return updated record is the same, likewise on airtable.
I don’t get any error message so I think I have the solution by downloading and rename locally then upload, but I don’t want to do that, not clean.

If you have any ideas :confused:

1 Reply 1

Yeah, this is a bit of a challenge because of certain Airtable constraints and aspects of their attachment architecture. It is possible though as demonstrated in this video. I used a script block for this example, but it can be done with any API call as well.

Script Used in the Video

/*

   ***********************************************************
   ScriptBloqs - Attachments
   Copyright (c) 2020 by Global Technologies Corporation
   ALL RIGHTS RESERVED
   ***********************************************************
   
*/

output.markdown('# Attachments Field');

// get the name of the table
let table = base.getTable("Airdrop");

// get the records from this table
let records = await table.selectRecordsAsync();

// Update the records
for (let record of records.records) {

    if (record.getCellValue("Images"))
    {

        output.inspect(record.getCellValue("Images"));

        // get the current image
        let oThisImage = record.getCellValue("Images");
        output.markdown("Current Image Name: " + oThisImage[0].filename);

        // change the name
        oThisImage[0].filename = record.getCellValue("New Image Name")
        output.markdown("New Image Name: " + oThisImage[0].filename);

        await table.updateRecordAsync(record, {
            "New Images" : [{
                "filename" : oThisImage[0].filename,
                "url" : oThisImage[0].url
            }]
        });

    }
}