Item has no binary field - mp3 file in base64

Describe the problem/error/question

I’m trying to download an mp3 file using a http request node and then write that file to the disk.

The http request returns something (as indicated in the box in n8n with the “download” link) - and what seems to be a base64-encoded string as the response.

I’m having trouble figuring out the issue of why we’re getting the many errors we’re getting when trying to execute the “write files to disk” node.

How can I then write that file to the disk? I tried adding a “convert to file” node to move the base64 string to file and then pass it to read/write files from disk but I’m getting a “The value in “[object Object]” is not set” in the “convert to file” node.

I’ve also tried doing a manual conversion of the base64 string to binary using a code node, & provided it as the return object in the format [[{ binary: { data: binaryData }}]; These are the various methods that were tested (below) - and one’s return data.

// must decode the string to a binary file type.

// function convertToBinary(string) {
//     let binaryString = '';

//     for (const char of string) {
//         const codePoint = char.codePointAt(0);
//         const binaryValue = codePoint.toString(2);
//         binaryString += binaryString.padStart(8, '0') + ' ';
//     }

//     const result = binaryString.trim();

//     let binary = new Uint8Array(result.length);
//     for (var i = 0; i < result.length; i++) {
//        binary[i] = result.charCodeAt(i);
//     }

//     return binary;
// }

// Function to decode a base64-encoded string and convert it to Uint8Array
// function base64ToUint8Array(base64) {
//     // Decode base64 to a Buffer
//     const buffer = Buffer.from(base64, 'base64');
    
//     // Convert Buffer to Uint8Array
//     const uint8Array = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
    
//     return uint8Array;
// }

// function convertToBinary(string) {
//     // Create a Uint8Array with the length of the string
//     const binaryArray = new Uint8Array(string.length);

//     // Populate the Uint8Array with binary data
//     for (let i = 0; i < string.length; i++) {
//         const codePoint = string.charCodeAt(i); // Get the character code
//         binaryArray[i] = codePoint; // Directly assign to Uint8Array
//     }

//     return binaryArray;
// }

function convertToBinary(string) {
    // Decode base64 string to binary data
    return Buffer.from(string, 'base64');
}

const base64Data = $input.first().binary.data.data;
// console.log(base64Data);
const binaryData = convertToBinary(base64Data);
console.log(binaryData);
return [{ binary: { data: binaryData }}];

Sometimes it returns what appears to be binary:

What is the error message (if any)?

When using Convert File Node: The value in “[object Object]” is not set - from the “convert to file” node.

When parsing Base64 to binary: The item has no binary field ‘[object Object]’ [item 0]

The documentation isn’t clear at all on how to work with files…

  • What am I doing wrong?
  • Is this potentially an issue with the API endpoint providing the wrong response format?
  • Am I not returning the right data structure from the code node properly?

Thanks in advance!

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.)

Can’t share full workflow because it has some credentials in it (in the http request). But here are the two workflows after the http request node runs.

Share the output returned by the last node

The error codes above.

Information on your n8n setup

  • n8n version: 1.41.1
  • Database (default: SQLite): Default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Not sure?
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Cloudron install (Docker?) in Digital Ocean
  • Operating system: Linux Ubuntu 22.2 LTS

Hey @lanab,

Welcome to the community :cake:

I suspect the issue is where you are using the {{ $binary }} expression instead of inputting the name of the field (default is data) that contains the binary data. This is assuming the HTTP Request node is actually outputting a binary file.