mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(NocoDB Node): Download attachments (#8235)
## Summary PR fixes Get Many fails to execute when Download Attachments is set to true  ## Related tickets and issues https://community.n8n.io/t/nocodb-unable-to-download-file/33333 https://linear.app/n8n/issue/NODE-960/nocodb-row-get-many-fails-to-execute-when-download-attachments-is-set
This commit is contained in:
parent
8a78ae1739
commit
43e8e5e540
|
@ -16,6 +16,7 @@ interface IAttachment {
|
||||||
title: string;
|
title: string;
|
||||||
mimetype: string;
|
mimetype: string;
|
||||||
size: number;
|
size: number;
|
||||||
|
signedUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,12 +43,15 @@ export async function apiRequest(
|
||||||
|
|
||||||
query = query || {};
|
query = query || {};
|
||||||
|
|
||||||
|
if (!uri) {
|
||||||
|
uri = baseUrl.endsWith('/') ? `${baseUrl.slice(0, -1)}${endpoint}` : `${baseUrl}${endpoint}`;
|
||||||
|
}
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
method,
|
method,
|
||||||
body,
|
body,
|
||||||
qs: query,
|
qs: query,
|
||||||
uri:
|
uri,
|
||||||
uri || baseUrl.endsWith('/') ? `${baseUrl.slice(0, -1)}${endpoint}` : `${baseUrl}${endpoint}`,
|
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -109,11 +113,14 @@ export async function downloadRecordAttachments(
|
||||||
const element: INodeExecutionData = { json: {}, binary: {} };
|
const element: INodeExecutionData = { json: {}, binary: {} };
|
||||||
element.json = record as unknown as IDataObject;
|
element.json = record as unknown as IDataObject;
|
||||||
for (const fieldName of fieldNames) {
|
for (const fieldName of fieldNames) {
|
||||||
|
let attachments = record[fieldName] as IAttachment[];
|
||||||
|
if (typeof attachments === 'string') {
|
||||||
|
attachments = jsonParse<IAttachment[]>(record[fieldName] as string);
|
||||||
|
}
|
||||||
if (record[fieldName]) {
|
if (record[fieldName]) {
|
||||||
for (const [index, attachment] of jsonParse<IAttachment[]>(
|
for (const [index, attachment] of attachments.entries()) {
|
||||||
record[fieldName] as string,
|
const attachmentUrl = attachment.signedUrl || attachment.url;
|
||||||
).entries()) {
|
const file: Buffer = await apiRequest.call(this, 'GET', '', {}, {}, attachmentUrl, {
|
||||||
const file: Buffer = await apiRequest.call(this, 'GET', '', {}, {}, attachment.url, {
|
|
||||||
json: false,
|
json: false,
|
||||||
encoding: null,
|
encoding: null,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue