Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions components/google_drive/actions/download-file/download-file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
key: "google_drive-download-file",
name: "Download File",
description: "Download a file. [See the documentation](https://developers.google.com/drive/api/v3/manage-downloads) for more information",
version: "0.1.10",
version: "0.1.13",
type: "action",
props: {
googleDrive,
Expand Down Expand Up @@ -47,6 +47,7 @@ export default {
directory](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory)
(e.g., \`/tmp/myFile.csv\`)
`),
optional: true,
},
mimeType: {
type: "string",
Expand Down Expand Up @@ -88,8 +89,19 @@ export default {
});
},
},
getBufferResponse: {
type: "boolean",
label: "Get Buffer Response",
description: "Whether to return the file content as a buffer instead of writing to a file path",
optional: true,
},
},
async run({ $ }) {
// Validate that filePath is provided when not getting raw response
if (!this.getBufferResponse && !this.filePath) {
throw new Error("File Path is required when not using Get Buffer Response");
}

// Get file metadata to get file's MIME type
const fileMetadata = await this.googleDrive.getFile(this.fileId, {
fields: "name,mimeType",
Expand All @@ -113,14 +125,30 @@ export default {
alt: "media",
});

if (this.getBufferResponse) {
$.export("$summary", `Successfully retrieved raw content for file "${fileMetadata.name}"`);

// Convert stream to buffer
const chunks = [];
for await (const chunk of file) {
chunks.push(chunk);
}
const buffer = Buffer.concat(chunks);

return {
fileMetadata,
content: buffer,
};
}

// Stream file to `filePath`
const pipeline = promisify(stream.pipeline);
const filePath = this.filePath.includes("tmp/")
? this.filePath
: `/tmp/${this.filePath}`;
await pipeline(file, fs.createWriteStream(filePath));
$.export("$summary", `Successfully downloaded the file, "${fileMetadata.name}"`);
return {
return {
fileMetadata,
filePath,
};
Expand Down
2 changes: 1 addition & 1 deletion components/google_drive/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/google_drive",
"version": "1.0.1",
"version": "1.0.2",
"description": "Pipedream Google_drive Components",
"main": "google_drive.app.mjs",
"keywords": [
Expand Down
Loading