I have a table in which images are automatically uploaded from our server (see screenshot). These image files are then sent to s3 for further manipulation and need a more meaningful filename. I tried to follow this video https://www.youtube.com/watch?v=qUPQoXQQATc which I feel is almost working but I have some errors which I can't figure out. This is my code so far:
const imageAttachment = base.getTable("Pre Mock Prod (PB)");
const recordid = input.config()["recordid"];
const recordToUpdate = await imageAttachment.selectRecordAsync(recordid)
let title = recordToUpdate?.getCellValue("mockup_id")
let imageField = recordToUpdate?.getCellValue("mockUpFiles")
let newImageField = []
if (imageField){
for ( let [image, imageNumber] of imageField.entries()){
console.log(image, imageNumber);
let findExtension = image.filename.match(/\w+_\d+\.\w+$/)||[""]
let extension = findExtension[0]
console.log(extension);
let fileSpecifcName = imageNumber>0 ? "-" + (imageNumber) : ""
newImageField.push ( {
url:image.url,
filename: title + fileSpecifcName + extension
})
}
console.log("New Image Field Array", newImageField)
await imageAttachment.updateRecordsAsync(recordid,
{
mockUpFiles: newImageField
})
}
This is a copy or my table:
https://airtable.com/shrS1aPnJ6YDPUsrN/tbltBWGWBNAKbDOIl