-
-
Save nocodesupplyco/c1a8bf58b66cc98f0a5a1a1404b79b6d to your computer and use it in GitHub Desktop.
Get Image Size w/ Airtable Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define settings fields and descriptions | |
const config = input.config({ | |
title: "Get Image Size", | |
description: "Get the size of images for each record in a specific view. Script created by [Base Scripts](https://nocodesupply.co/basescripts) — use at your own discretion.", | |
items: [ | |
input.config.table("tableSelect", { | |
label: "Table", | |
description: "Select the table where there are images to check.", | |
}), | |
input.config.view("viewSelect", { | |
label: "View", | |
description: "Select the view where there are images to check.", | |
parentTable: "tableSelect", | |
}), | |
input.config.field("imageSelect", { | |
label: "Image Field", | |
description: "Select the attachment field that contains the images to check.", | |
parentTable: "tableSelect", | |
}), | |
input.config.field("imageSizeSelect", { | |
label: "Image Size Field", | |
description: "Select the number field where the image size should be output.", | |
parentTable: "tableSelect", | |
}), | |
], | |
}); | |
// Set settings to variables | |
const configTable = config.tableSelect.name; | |
const configView = config.viewSelect.name; | |
const configImage = config["imageSelect"].name; | |
const configImageSize = config["imageSizeSelect"].name; | |
// Set table and view based on settings | |
let table = base.getTable(configTable); | |
let view = table.getView(configView); | |
// Get all image fields | |
let result = await view.selectRecordsAsync({ fields: [configImage] }); | |
// Loop through each image field to get size | |
for (let record of result.records) { | |
// Get image size from cell value | |
let imageSize = record.getCellValue(configImage)[0].size / 1000; | |
// Update record with image size | |
await table.updateRecordAsync(record, { | |
[configImageSize]: imageSize, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment