Feb 12, 2023 11:23 AM
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:
Feb 12, 2023 02:05 PM
I think I am nearly there with this but it only updates 1 record:
Feb 13, 2023 12:23 AM
This is as close as I can get. If someone could let me know how to edit the code so that the file name is renamed as it is created or updated that would be great. Currently, this only works if I update the record which isn't ideal:
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 [imageNumber, image] of imageField.entries()) {
console.log(image, imageNumber);
let findExtension = image.filename.match(/\w+_\d+\.\w+$/) || [""];
let extension = findExtension[0];
console.log(extension);
let fileSpecificName = imageNumber > 0 ? "-" + (imageNumber) : "";
newImageField.push({
url: image.url,
filename: title + fileSpecificName + extension
});
}
console.log("New Image Field Array", newImageField);
await imageAttachment.updateRecordsAsync([{
id: recordid,
fields: {
mockUpFiles: newImageField
}
}]);
}