How to read the raw content from the file

Describe the problem/error/question

We have a file *.key which has the raw secret key. We need to read the sting and pass it as Auth Token to the Http Node call.
We could not read the file content. We used ‘Read/Write Files from Disk’, but it gives only the file metadata, not the raw content.
Any way to achieve this scenario?

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

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

Hi @shakthipsg! You can use the Read/Write File node which you can enable from the docker settings

To load your .key file then pass its binary output to the extract from file node, to get the raw string which you can directly use in HTTP node as a Auth token

The Read/Write Files from Disk node outputs the file as binary data so you won’t see the actual content in the JSON output, it’s under the Binary tab. After that node just add an “Extract From File” node and set the operation to “Extract From Text File”, that’ll convert the binary into a plain string you can reference in your HTTP Request node’s auth header with an expression like {{ $json.data }}.

Yeah the Read/Write Files from Disk node only gives you binary data, you need to convert it. Easiest way is to add a Code node right after it with something like:

const buffer = await this.helpers.getBinaryDataBuffer(0, 'data');
return [{ json: { key: buffer.toString('utf8').trim() } }];

Then just reference {{ $json.key }} in your HTTP node’s auth header.

This is the output binary data from ‘Read/Write Files from Disk’

1 Like

{
“nodes”: [
{
“parameters”: {
“operation”: “text”,
“binaryPropertyName”: “={{ $json }}”,
“options”: {
“keepSource”: “binary”
}
},
“type”: “n8n-nodes-base.extractFromFile”,
“typeVersion”: 1.1,
“position”: [
15856,
3232
],
“id”: “d46f19c3-6687-4b71-ad55-17299ddbff34”,
“name”: “Extract from File”
},
{
“parameters”: {
“fileSelector”: “C:\Users\Administrator\.n8n-files\ff9bff85-2a90-4a5a-86e6-ca42890b934c.key”,
“options”: {
“dataPropertyName”: “data”
}
},
“type”: “n8n-nodes-base.readWriteFile”,
“typeVersion”: 1.1,
“position”: [
15680,
3232
],
“id”: “9122c7fc-1a56-4dd7-bc41-650fb6054a9c”,
“name”: “Read/Write Files from Disk”
}
],
“connections”: {
“Extract from File”: {
“main”: [

]
},
“Read/Write Files from Disk”: {
“main”: [
[
{
“node”: “Extract from File”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “26c9ba787d1a2e7f1a69dee00e7e18ce16f0db13de92e898433e374ee4939051”
}
}

@shakthipsg Now attach an Extract from File here, and then read your key using common json.data and then pass that key to HTTP node where you want it to be.

1 Like

Thank you @achamm @Anshul_Namdev , This works.

1 Like

Hi @shakthipsg !
we’re glad to hear that! please consider marking the most appropriate answer to your question as the solution. This helps the community and the supporters.

1 Like

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