How to rename the downloaded file?

Describe the problem/error/question

I’ve downloaded a file from google drive and I want to rename the binary file using a field name but I can’t seem to get the output right. I want to later use it upload to another service. How can I fix this?

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 2.2.3
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: Ubuntu 24.04 LTS
1 Like

Hey @Ruriko
You’re very close the problem is just in the Code node.

  1. Your Merge is correct
  • Using Merge → Combine → By Position is exactly how you combine the JSON from Edit Fields with the binary from Download file so that both json and binary are available in one item.
  1. Fix the Code node

Your current JS:

$input.item.binary.data.fileName = '${json.title}_{json.number}.zip'

return $input.item;

won’t interpolate json.title / json.number. Use the merged item and a template literal:

const item = $input.item;

// item.json now has title & number from Edit Fields
// item.binary.data comes from Google Drive "Download file" (default field name is "data") [[Download file](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.googledrive/file-operations/#download-a-file)]

item.binary.data.fileName = `${item.json.title}_${item.json.number}.zip`;

return item;

Make sure the Code node is set to Run Once for Each Item (the default for Code v2).

  1. Using it in the next upload node

When you upload to another service (for example Google Drive “Upload”):

  • Input Data Field Name should be data, because that’s the binary key containing your renamed file.

After this, the upload node will receive:

  • binary.data → file content + renamed fileName

  • json.title / json.number still available if needed.

So with this you should be able to rename that file, let me know if this helps

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.