Skip to content

Commit 1276751

Browse files
committed
Get blob
1 parent 0e76fdc commit 1276751

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

nodes/AzureBlobStorage/AzureBlobDescription.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ export const blobOperations: INodeProperties[] = [
7474
description: 'List blobs inside a container',
7575
action: 'Get many blobs',
7676
},
77+
{
78+
name: 'Get',
79+
value: 'get',
80+
description: 'Get the binary data from a blob',
81+
action: "Get a blob"
82+
}
7783
],
7884

7985
default: 'getMany',
@@ -83,6 +89,7 @@ export const blobOperations: INodeProperties[] = [
8389
name: 'container',
8490
type: 'string',
8591
noDataExpression: true,
92+
required:true,
8693

8794
displayOptions: {
8895
show: {
@@ -101,7 +108,7 @@ export const blobOperations: INodeProperties[] = [
101108
displayOptions: {
102109
show: {
103110
resource: ['blob'],
104-
operation: ['upload'],
111+
operation: ['upload', 'get'],
105112
},
106113
},
107114
description:

nodes/AzureBlobStorage/AzureBlobStorage.node.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,36 @@ export class AzureBlobStorage implements INodeType {
8585
arr.push(blob);
8686
}
8787
returnData.push.apply(returnData, arr as IDataObject[]);
88+
} else if (operation === 'get') {
89+
const blobName = this.getNodeParameter('blobName', i) as string;
90+
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
91+
const downloadBlockBlobResponse = await blockBlobClient.download();
92+
93+
const newItemBinary: IBinaryKeyData = {};
94+
const buffer = await streamToBuffer(downloadBlockBlobResponse.readableStreamBody) as Buffer;
95+
newItemBinary.data = await this.helpers.prepareBinaryData(buffer);
96+
newItemBinary.data.mimeType = downloadBlockBlobResponse.contentType;
97+
98+
returnData.push({
99+
json: {
100+
"blobName": blobName,
101+
"blobType": downloadBlockBlobResponse.blobType,
102+
"contentEncoding" : downloadBlockBlobResponse.contentEncoding,
103+
"contentLanguage" : downloadBlockBlobResponse.contentLanguage,
104+
"contentLength" : downloadBlockBlobResponse.contentLength,
105+
"contentType" : downloadBlockBlobResponse.contentType,
106+
"lastAccessed" : downloadBlockBlobResponse.lastAccessed,
107+
"lastModified" : downloadBlockBlobResponse.lastModified,
108+
"leaseDuration" : downloadBlockBlobResponse.leaseDuration,
109+
"leaseState" : downloadBlockBlobResponse.leaseState,
110+
"leaseStatus" : downloadBlockBlobResponse.leaseStatus,
111+
},
112+
pairedItem: {
113+
item: i,
114+
},
115+
binary: Object.keys(newItemBinary).length === 0 ? undefined : newItemBinary,
116+
});
117+
88118
} else if (operation === 'upload') {
89119
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i) as string;
90120

@@ -131,3 +161,17 @@ export class AzureBlobStorage implements INodeType {
131161
return [this.helpers.returnJsonArray(returnData)];
132162
}
133163
}
164+
165+
166+
async function streamToBuffer(readableStream: NodeJS.ReadableStream) {
167+
return new Promise((resolve, reject) => {
168+
const chunks: Buffer[] = [];
169+
readableStream.on("data", (data: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>) => {
170+
chunks.push(data instanceof Buffer ? data : Buffer.from(data));
171+
});
172+
readableStream.on("end", () => {
173+
resolve(Buffer.concat(chunks));
174+
});
175+
readableStream.on("error", reject);
176+
});
177+
}

0 commit comments

Comments
 (0)