I’m a bit stuck with the code for dealing with binary data, in my custom node dev process.
One of my functions in GenericFunctions.ts, that deals with downloading binary content of files, is facing issues and is defined as follows:
export async function directusApiAssetRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, path: string, ID: string, dataPropertyName: string, qs: IDataObject = {} ): Promise<any> { // tslint:disable-line:no-any
const credentials = await this.getCredentials('directusApi') as { url: string, accessToken: string };
if (credentials === undefined) {
throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
}
const params = credentials;
const url = params.url!.replace(/\/$/, "") || null;
const accessToken = params.accessToken! || null;
const optionsAsset: OptionsWithUri = {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
},
method,
qs,
uri: `${url}/${path.replace(/^\//, "")}`,
json: true,
};
try {
const resFile = await this.helpers.request!(optionsFile);
const file = resFile.data;
const res: any = await this.helpers.request!(optionsAsset);
const binaryData = Buffer.from(res);
const data = binaryData.toString('base64');
const binary = {
[dataPropertyName]: {
data: "",
fileName: 'fileName',
mimeType: 'mimeType'
} as IBinaryData
};
binary![dataPropertyName] = await this.helpers.prepareBinaryData(binaryData);
const json = {};
const result : INodeExecutionData = {
json,
binary
};
return result ;
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}
};
But, i’m seeing this error while/before compiling the code:
nodes/Directus/GenericFunctions.ts:136:56 - error TS2339: Property 'prepareBinaryData' does not exist on type '{ prepareBinaryData(binaryData: Buffer, filePath?: string | undefined, mimeType?: string | undefined): Promise<IBinaryData>; getBinaryDataBuffer(itemIndex: number, propertyName: string): Promise<...>; request: RequestPromiseAPI; requestOAuth2(this: IAllExecuteFunctions, credentialsType: string, requestOptions: (UriO...'.
Property 'prepareBinaryData' does not exist on type '{ request?: RequestPromiseAPI | undefined; requestOAuth2?: ((this: IAllExecuteFunctions, credentialsType: string, requestOptions: (UriOptions & CoreOptions) | RequestPromiseOptions, oAuth2Options?: IOAuth2Options | undefined) => Promise<...>) | undefined; requestOAuth1?(this: IAllExecuteFunctions, credentialsType: s...'.
136 binary![dataPropertyName] = await this.helpers.prepareBinaryData(binaryData);
~~~~~~~~~~~~~~~~~
Would appreciate any help in figuring this out!