can you share a working example of create
Hi
thanks for the library google's original API is kind of low level
for some reason, I am having trouble uploading files
create method is not on the googleDriveInstane
and there is no example in the readme for using it
thanks
Hello,
I have the same problem. I figured out that there isn't any create function into the library. Instead there is function writeFile and writePDFFile that I am using because I want to upload a PDF file.
But it has a bug. It can't handle the file path
(node:51) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type object
at Object.open (fs.js:409:3)
at P (/home/node/app/node_modules/pify/index.js:49:6)
at new Promise (<anonymous>)
at Object.open (/home/node/app/node_modules/pify/index.js:11:9)
at module.exports (/home/node/app/node_modules/read-chunk/index.js:12:13)
**at NodeGoogleDrive.writeFile (/home/node/app/node_modules/node-google-drive/index.js:595:10)**
at ClientService.ExampleOperations (/home/node/app/src/services/client.ts:271:52)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:51) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:51) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I think it should be something related to this https://stackoverflow.com/a/57371234
The problem is that the version in NPM repository is outdated.
The author looks like isn`t avaiable. I forked the repository and published a new one project to NPM
https://www.npmjs.com/package/google-drive-connect
npm i google-drive-connect
const NodeGoogleDrive = require('google-drive-connect');
const YOUR_ROOT_FOLDER = '******',
PATH_TO_CREDENTIALS = path.resolve(`credentials.json`);
const creds_service_user = require(PATH_TO_CREDENTIALS);
const googleDriveInstance = new NodeGoogleDrive({
ROOT_FOLDER: YOUR_ROOT_FOLDER
});
let gdrive = await googleDriveInstance.useServiceAccountAuth(
creds_service_user
);
const fileName = `${__dirname}/tmp/file.pdf`;
let uploadResponse = await googleDriveInstance.create({
source:fs.createReadStream(fileName),
name: 'MyDocument.pdf',
parentFolder: YOUR_ROOT_FOLDER,
mimeType: 'application/pdf'
});
This code worked for me.
@ediaz-inteliti . thank you very much. I was also having problem with the create method.
@ediaz-inteliti However there is one issue with your version, whenever I pass ROOT_FOLDER = null, it throws an error. While the old version (original node-google-drive) works perfectly when I pass ROOT_FOLDER = null. Can you please look into this issue. It will be really helpful
The problem is that the version in NPM repository is outdated.
The author looks like isn`t avaiable. I forked the repository and published a new one project to NPM
https://www.npmjs.com/package/google-drive-connect
npm i google-drive-connectconst NodeGoogleDrive = require('google-drive-connect'); const YOUR_ROOT_FOLDER = '******', PATH_TO_CREDENTIALS = path.resolve(`credentials.json`); const creds_service_user = require(PATH_TO_CREDENTIALS); const googleDriveInstance = new NodeGoogleDrive({ ROOT_FOLDER: YOUR_ROOT_FOLDER }); let gdrive = await googleDriveInstance.useServiceAccountAuth( creds_service_user ); const fileName = `${__dirname}/tmp/file.pdf`; let uploadResponse = await googleDriveInstance.create({ source:fs.createReadStream(fileName), name: 'MyDocument.pdf', parentFolder: YOUR_ROOT_FOLDER, mimeType: 'application/pdf' });This code worked for me.
Hey, I tried using your package but it also gave another error
\node_modules\node-google-drive\index.js:605
return _this.service.files.createAsync({
^
TypeError: Cannot read properties of null (reading 'createAsync')