How to pass Binary file to next node for upload

i guys i am new to node and n8n. i am using Google drive node (using download option ) to get a file and now I am trying to pas the binary file to next node

Here is my workflow

after executing the google node i am getting the binary file

in the next node i have to upload this file to another endpoint . i am confused how can i get the previses binary file and pass it to my api

given below my code snippet

const binaryPropertyName = this.getNodeParameter(‘binaryPropertyName’, 0) as string;

const thePdfFile = Buffer.from(binaryPropertyName, ‘base64’);

const options: OptionsWithUri = {
headers: {
‘Accept’: ‘application/json’,
‘Content-Type’: ‘multipart/form-data’,
‘X-API-KEY’: ‘MY_API_KEY’,
},
method: ‘POST’,
body: {
files: thePdfFile
},
uri: MY_END_POINT,
json: true,
};

            responseData = await this.helpers.request(options);

Hey @Shehryar,

Welcome to the community :rocket:

If you are writing your own node I would take a look at what other nodes are doing that upload files maybe the Mindee node as a starting point.

Below is how it fetches the binary data so the trick is to have an option that you can input the property name of the binary object so looking at the google output you have data. This would be referenced as inputItem[data] using the ibinarydata type and from there you can get your buffer and it should be all good.

const item = items[i].binary as IBinaryKeyData;
const binaryData = item[binaryPropertyName] as IBinaryData;
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);

It looks like you are fairly close you are getting the property name as a string it should be a case of taking the above and tweaking for your code and you will be posting data.

@Jon thanks for helping me out now i am able to get the binary data i have check them in the logs .
yes you are right i am writing my custom node, now i am getting error “source.on is not a function”. here is my code.

here is the error. please help me out how can i solve it.

Hey @Shehryar,

It is hard to say what is happening there without seeing the full error message.

I would probably start by putting in some checks to make sure none of the options are undefined, If I was to take a guess I would say the issue is with the formData it could be something silly like files needs to be file

@Jon thanks a lot for helping me . I figure it out by your clue

1 Like

Sweet, happy automating :rocket: