[βœ… Solution] Can file names be changed via automation / calculation / script?

If a file is uploaded into the system, could the filename be changed according to an algorithm?

1 Like

Hi @dirk_s,

thanks for your question - sounds like an interesting use case!

Currently, as files are considered immutable in Tape, there is no way to change their name β€œin place”. However, one can just upload the file again and provide a different filename, then reattach the file to the record.

The strategy could be as follows:

  1. Read your Tape internal file ID and existing filename from your record
  2. Upload the file via the developer API
  3. Reattach the file by updating your file field value

The script action that I used in my test case contained the following code:

// TODO: use your file field variables here
const existingFileUrl = rename_uploaded_file_field_files_file_url;
const existingFileName = rename_uploaded_file_field_files_filename;

// change file name according to some algorithm:
const newFileName = 'NEW-' + existingFileName;

const {data: file_content} = await http.get(existingFileUrl, {responseEncoding: 'binary'});
const encoded_file_content = Buffer.from(file_content, 'binary')
const new_upload = await tape.File.upload({filename:newFileName, source: encoded_file_content });

var_new_file_id = new_upload.data.file_id;

Ultimately, the final workflow looked like this:

It replaces an uploaded file’s name by adding a β€œNEW-” prefix. You can of course use your own algorithm to determine the desired filename. If this needs to work with multiple files, one might need to enhance a the logic a bit.

Let me know if that works, all excited!

Cheers
Tim

2 Likes

We could also delete the old one then?

1 Like

Once the reference to the old file is removed from the record, it will be garbage collected by Tape (as there is no reference to is anymore) and would thereby be deleted soon.

Does that answer your question?

Cheers
Tim

1 Like

Nice one, but how would this automation look if there is more than one file per field? How can I loop your solution and add a counter? @Tim

  • Bild_1.jpg
  • Bild_2.jpg
  • …

Bonus:

image

How can I easily adapt this script so that files 1–X of this field are renamed?

@Tim or @dirk_s, could someone please help me get this running?

@Roman Not Tim or Dirk but assuming you want to do something like:
CleanShot 2025-12-10 at 13.24.04
this is what does the above:

const files = filerename_field_files_iterable;
console.info(JSON.stringify(files, null, 2));

const baseName = `${filerename_field_name_value}-`;
let n = 1; // start numbering from 1
const newFileIds = []; // array to store new file IDs

for (const file of files) {
  try {
    // Generate new filename
    const newFileName = `${baseName}${n}.pdf`;

    // Fetch file content
    const { data: file_content } = await http.get(file.link, { responseEncoding: 'binary' });

    // Encode the file content
    const encoded_file_content = Buffer.from(file_content, 'binary');

    // Upload the file with the new name
    const new_upload = await tape.File.upload({
      filename: newFileName,
      source: encoded_file_content
    });

    // Store the new file ID
    newFileIds.push(new_upload.data.file_id);

    // Increment counter
    n++;

  } catch (err) {
    console.error(`Failed to process file ${file.filename}:`, err);
  }
}

console.log('New file IDs:', newFileIds);

await tape.Record.update(current_record_id{
    fields: {
        files: newFileIds
    }
});

the filerename_field_files_iterable is available in automations for multi-file fields and that will give you an array like:


  {
    "file_id": 7157389,
    "name": "0.pdf",
    "link": "https://s3.eu-central-1.amazonaws.com/tape-attachments/3a35c275a5bbe2dd323c07b7080b6c?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=9df14ed60ac903b62819134d27f47c000475d7f168232a86de3b7beb79fa36d0&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%220.pdf%22&response-content-type=charset%3Dutf-8",
    "view_url": "https://s3.eu-central-1.amazonaws.com/tape-attachments/3a35c275a5bbe2dd323c07b7080b6c?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=ec2e43d73b9642927eea129f0b826916784c966cf9f0de7d0fe8826f420d2443&X-Amz-SignedHeaders=host&response-content-type=application%2Fpdf%3B%20charset%3Dutf-8",
    "download_url": "https://s3.eu-central-1.amazonaws.com/tape-attachments/3a35c275a5bbe2dd323c07b7080b6c?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=9df14ed60ac903b62819134d27f47c000475d7f168232a86de3b7beb79fa36d0&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%220.pdf%22&response-content-type=charset%3Dutf-8",
    "created_on": "2025-12-10 13:23:30"
  },
  {
    "file_id": 7157390,
    "name": "1.pdf",
    "link": "https://s3.eu-central-1.amazonaws.com/tape-attachments/df953e19a43718c6a745d9f202b451?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=aed7c8368cb95a7e986e22aaf4c6fc3789454e5aa95d0929baac2b5346070d59&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%221.pdf%22&response-content-type=charset%3Dutf-8",
    "view_url": "https://s3.eu-central-1.amazonaws.com/tape-attachments/df953e19a43718c6a745d9f202b451?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=54eedb7220c0dcba9e773579713bfae78928358534e8ad057e7e063f1a00ce88&X-Amz-SignedHeaders=host&response-content-type=application%2Fpdf%3B%20charset%3Dutf-8",
    "download_url": "https://s3.eu-central-1.amazonaws.com/tape-attachments/df953e19a43718c6a745d9f202b451?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=aed7c8368cb95a7e986e22aaf4c6fc3789454e5aa95d0929baac2b5346070d59&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%221.pdf%22&response-content-type=charset%3Dutf-8",
    "created_on": "2025-12-10 13:23:32"
  },
  {
    "file_id": 7157393,
    "name": "2.pdf",
    "link": "https://s3.eu-central-1.amazonaws.com/tape-attachments/4ba3879984fb8a4ab8604344be9e25?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=c53adc4dced43bd10db63e574a82093aa2ca9dbe67ae44af5f5e4be7c7b61a12&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%222.pdf%22&response-content-type=charset%3Dutf-8",
    "view_url": "https://s3.eu-central-1.amazonaws.com/tape-attachments/4ba3879984fb8a4ab8604344be9e25?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=4e405120a45b0c6b87f6499451ae47a046cfb2b720436f506583c3699e111e70&X-Amz-SignedHeaders=host&response-content-type=application%2Fpdf%3B%20charset%3Dutf-8",
    "download_url": "https://s3.eu-central-1.amazonaws.com/tape-attachments/4ba3879984fb8a4ab8604344be9e25?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=c53adc4dced43bd10db63e574a82093aa2ca9dbe67ae44af5f5e4be7c7b61a12&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%222.pdf%22&response-content-type=charset%3Dutf-8",
    "created_on": "2025-12-10 13:23:36"
  },
  {
    "file_id": 7157400,
    "name": "3.pdf",
    "link": "https://s3.eu-central-1.amazonaws.com/tape-attachments/03b26124c6dcf44a77b2363cfc9088?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=33ccd9a0d62cfcdf157d6a50d5ee386dc8e176f54f18778467dfe0a420c9cfc1&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%223.pdf%22&response-content-type=charset%3Dutf-8",
    "view_url": "https://s3.eu-central-1.amazonaws.com/tape-attachments/03b26124c6dcf44a77b2363cfc9088?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=78a625dc1357fd2b92e8c91abe5c43ae70be61103f1c53c569129e5fe7bd2131&X-Amz-SignedHeaders=host&response-content-type=application%2Fpdf%3B%20charset%3Dutf-8",
    "download_url": "https://s3.eu-central-1.amazonaws.com/tape-attachments/03b26124c6dcf44a77b2363cfc9088?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=33ccd9a0d62cfcdf157d6a50d5ee386dc8e176f54f18778467dfe0a420c9cfc1&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%223.pdf%22&response-content-type=charset%3Dutf-8",
    "created_on": "2025-12-10 13:23:39"
  },
  {
    "file_id": 7157413,
    "name": "4.pdf",
    "link": "https://s3.eu-central-1.amazonaws.com/tape-attachments/99ffadc4c9bd65a16377d289d5bbc2?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=dc0bd493f561af6d41cf4f5bc5e846261368fef0e7d555af439bf1abf77b391e&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%224.pdf%22&response-content-type=charset%3Dutf-8",
    "view_url": "https://s3.eu-central-1.amazonaws.com/tape-attachments/99ffadc4c9bd65a16377d289d5bbc2?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=66a7091c910bd3770bb0468a036d81634942aa57bd640bc7687b37776279a871&X-Amz-SignedHeaders=host&response-content-type=application%2Fpdf%3B%20charset%3Dutf-8",
    "download_url": "https://s3.eu-central-1.amazonaws.com/tape-attachments/99ffadc4c9bd65a16377d289d5bbc2?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=dc0bd493f561af6d41cf4f5bc5e846261368fef0e7d555af439bf1abf77b391e&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%224.pdf%22&response-content-type=charset%3Dutf-8",
    "created_on": "2025-12-10 13:23:43"
  },
  {
    "file_id": 7157434,
    "name": "5.pdf",
    "link": "https://s3.eu-central-1.amazonaws.com/tape-attachments/37d46186a0ba19890ccc02ffa15dff?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=d863fd4d076f1933523bed10faa8685eff2e3eaecde3f1f7d3b12535bcda0fcf&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%225.pdf%22&response-content-type=charset%3Dutf-8",
    "view_url": "https://s3.eu-central-1.amazonaws.com/tape-attachments/37d46186a0ba19890ccc02ffa15dff?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=91e58f93f8e90c165bcd4a59343c7bbeb4c28a36ae51b48bd932585d34913345&X-Amz-SignedHeaders=host&response-content-type=application%2Fpdf%3B%20charset%3Dutf-8",
    "download_url": "https://s3.eu-central-1.amazonaws.com/tape-attachments/37d46186a0ba19890ccc02ffa15dff?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVNOAIV5JPIBLTKIM%2F20251210%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20251210T132408Z&X-Amz-Expires=518400&X-Amz-Signature=d863fd4d076f1933523bed10faa8685eff2e3eaecde3f1f7d3b12535bcda0fcf&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3Bfilename%3D%225.pdf%22&response-content-type=charset%3Dutf-8",
    "created_on": "2025-12-10 13:23:47"
  }
]

then you can loop through them download, create new name, upload and then get the new file_id which we push into an array before replacing the files that were in file field with the new ones.

Hope that helps

4 Likes

Thanks so much, @Jason. I will try to implement this. :pray:

1 Like