Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can you share a working example of create #62

Open
shmuel-web opened this issue May 5, 2020 · 5 comments
Open

can you share a working example of create #62

shmuel-web opened this issue May 5, 2020 · 5 comments

Comments

@shmuel-web
Copy link

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

@ediaz-inteliti
Copy link

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

@ediaz-inteliti
Copy link

ediaz-inteliti commented May 13, 2020

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.

@aubierahul
Copy link

@ediaz-inteliti . thank you very much. I was also having problem with the create method.

@aubierahul
Copy link

@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

@LMeiraba
Copy link

LMeiraba commented Feb 17, 2023

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.

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants