googleapis version: 43.0.0I have the following piece of code:
const drive = google.drive({
version: 'v3',
auth: 'MYAPIKEYHERE'
});
const folderId = 'MYFOLDERIDHERE';
const fileMetadata = {
name: filename,
parents: [ folderId ]
};
const media = {
body: file
};
return new Promise((resolve, reject) => {
drive.files.create({
// @ts-ignore
resource: fileMetadata,
media: media,
fields: 'id'
// @ts-ignore
}, (err, result) => {
if (null !== err) {
reject(err);
} else {
resolve(result.id);
}
});
});
filename is a string and file a Buffer... I tried many combinations from StackOverflow, Github, and Google Docs but all of them gave me the following error:
TypeError: part.body.pipe is not a function
at createAPIRequestAsync (/home/farm/Documents/InventorySystemAPI/node_modules/googleapis-common/build/src/apirequest.js:182:31)
at Object.createAPIRequest (/home/farm/Documents/InventorySystemAPI/node_modules/googleapis-common/build/src/apirequest.js:41:9)
at Resource$Files.create (/home/farm/Documents/InventorySystemAPI/node_modules/googleapis/build/src/apis/drive/v3.js:660:37)
at /home/farm/Documents/InventorySystemAPI/dist/google/drive.js:39:21
at new Promise (<anonymous>)
at Object.<anonymous> (/home/farm/Documents/InventorySystemAPI/dist/google/drive.js:38:12)
at Generator.next (<anonymous>)
at /home/farm/Documents/InventorySystemAPI/dist/google/drive.js:7:71
at new Promise (<anonymous>)
at __awaiter (/home/farm/Documents/InventorySystemAPI/dist/google/drive.js:3:12)
at Object.exports.addToGDrive (/home/farm/Documents/InventorySystemAPI/dist/google/drive.js:13:43)
at Object.<anonymous> (/home/farm/Documents/InventorySystemAPI/dist/controllers/invoice.js:21:44)
at Generator.next (<anonymous>)
at /home/farm/Documents/InventorySystemAPI/dist/controllers/invoice.js:7:71
at new Promise (<anonymous>)
at __awaiter (/home/farm/Documents/InventorySystemAPI/dist/controllers/invoice.js:3:12)
The funny part is that following the Google Docs tutorial when I tried to create a 'credntials.json' file, it was given to me an API key.
@Fazendaaa can you share the logic you're using to load the file? are you using fs.createReadStream like in the sample?
@Fazendaaa how did you resolve it? I have been stuck with the same issue.
@Fazendaaa @rashikbhasin rather than using a Buffer, could you try passing:
body: fs.createReadStream('./path/to/file')
:point_up: I believe this is the API surface that it expects currently (I understand wanting to pass a buffer, this might be a feature request or gap in documentation).
Greetings folks! Haven't heard anything back in a while, so I'm closing this out. Please do let us know if you're still running into issues!
Most helpful comment
@Fazendaaa how did you resolve it? I have been stuck with the same issue.