1

I am using googleapi to export the file from a google drive. I have the following code in my export.js. When I run this file, even though i have given the mimeType it throws an error saying "The API returned an error: Error: Required parameter: mimeType"

var drive = google.drive({
  version: 'v3',
  auth: auth
});

var dest = fs.createWriteStream('./public/data/myfile.txt');
drive.files.export({
  fileId : fileID,
  mimeType : 'text/plain'
}, function(err, response) {
  if (err) {
  console.log('The API returned an error: ' + err);
  return;
  }
  console.log('Received %d bytes', response.length);
  fs.writeFileSync(dest, response);
});
1

2 Answers 2

2

Ohai! Maintainer here. When something like this happens, it's usually because there's some mismatch between the version of googleapis and google-auth-library. As far as the code is concerned, we have a full working copy here:

https://github.com/google/google-api-nodejs-client/blob/master/samples/drive/export.js

Now - on what to do. You need to make sure that a.) you are using the latest version of googleapis, and b.) you DO NOT have google-auth-library in your package.json. Please try:

$ npm uninstall --save google-auth-library $ npm install --save googleapis@28

Give that a shot and let me know how it goes :)

Sign up to request clarification or add additional context in comments.

1 Comment

for me it was updating packages as Justin suggested and do some little changes to code.. more info here: github.com/google/google-api-nodejs-client/issues/1098, thank you @justin-beckwith for your help
0

I think you can try it this way and make sure your file matches the mimeType you are requesting and maybe you need to say that you are accepting binary data.

drive.files.export({
   fileId: 'asxKJod9s79', // A Google Doc pdf
   mimeType: 'application/pdf'},
   { encoding: null }, // Make sure we get the binary data
   function (err, buffer) {
       // ...
       // convert and write the file
    });

Note that the API returns a buffer object and you need to convert and write it to a file. Refer this.

Or you can use this :

var fileId = '1ZdR3L3qP4Bkq8noWLJHSr_iBau0DNT4Kli4SxNc2YEo';
var dest = fs.createWriteStream('/tmp/resume.pdf');
drive.files.export({
  fileId: fileId,
  mimeType: 'application/pdf'
})
    .on('end', function () {
      console.log('Done');
    })
    .on('error', function (err) {
      console.log('Error during download', err);
    })
    .pipe(dest);

1 Comment

Thanks for the reply. I have tried these options as well. It didn't work for me. I get the same error "Error: Required parameter: mimeType"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.