@@ -18,7 +18,7 @@ export default {
1818 key : "google_drive-download-file" ,
1919 name : "Download File" ,
2020 description : "Download a file. [See the documentation](https://developers.google.com/drive/api/v3/manage-downloads) for more information" ,
21- version : "0.1.11 " ,
21+ version : "0.1.12 " ,
2222 type : "action" ,
2323 props : {
2424 googleDrive,
@@ -47,6 +47,7 @@ export default {
4747 directory](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory)
4848 (e.g., \`/tmp/myFile.csv\`)
4949 ` ) ,
50+ optional : true ,
5051 } ,
5152 mimeType : {
5253 type : "string" ,
@@ -93,8 +94,19 @@ export default {
9394 accessMode : "write" ,
9495 sync : true ,
9596 } ,
97+ getBufferResponse : {
98+ type : "boolean" ,
99+ label : "Get Buffer Response" ,
100+ description : "Whether to return the file content as a buffer instead of writing to a file path" ,
101+ optional : true ,
102+ } ,
96103 } ,
97104 async run ( { $ } ) {
105+ // Validate that filePath is provided when not getting raw response
106+ if ( ! this . getBufferResponse && ! this . filePath ) {
107+ throw new Error ( "File Path is required when not using Get Buffer Response" ) ;
108+ }
109+
98110 // Get file metadata to get file's MIME type
99111 const fileMetadata = await this . googleDrive . getFile ( this . fileId , {
100112 fields : "name,mimeType" ,
@@ -118,14 +130,30 @@ export default {
118130 alt : "media" ,
119131 } ) ;
120132
133+ if ( this . getBufferResponse ) {
134+ $ . export ( "$summary" , `Successfully retrieved raw content for file "${ fileMetadata . name } "` ) ;
135+
136+ // Convert stream to buffer
137+ const chunks = [ ] ;
138+ for await ( const chunk of file ) {
139+ chunks . push ( chunk ) ;
140+ }
141+ const buffer = Buffer . concat ( chunks ) ;
142+
143+ return {
144+ fileMetadata,
145+ content : buffer ,
146+ } ;
147+ }
148+
121149 // Stream file to `filePath`
122150 const pipeline = promisify ( stream . pipeline ) ;
123151 const filePath = this . filePath . includes ( "tmp/" )
124152 ? this . filePath
125153 : `/tmp/${ this . filePath } ` ;
126154 await pipeline ( file , fs . createWriteStream ( filePath ) ) ;
127155 $ . export ( "$summary" , `Successfully downloaded the file, "${ fileMetadata . name } "` ) ;
128- return {
156+ return {
129157 fileMetadata,
130158 filePath,
131159 } ;
0 commit comments