2

I am having a few issues with the Google Drive node.js library. I am trying to upload a picture to my google drive, I have authenticated previously hence the 'oauth2Client' object. This is taken nearly like for like from the example on the google docs.

var service = googleApi.drive('v3');
var fileMetadata = {
    'name': 'jpeg-home.jpg'
};
var media = {
    mimeType: 'image/jpeg',
    body: fs.createReadStream('./temp/downloads/jpeg-home.jpg')
};
service.files.create({
    auth: oauth2Client,
    resource: fileMetadata,
    media: media,
    fields: 'id'
}, function (err, file) {
    if (err) {
        console.error(err);
        return false;
    } else {
        console.log('File Id: ', file.id);
        return true;
    }
});

The response I am getting is an error of:

Error: Invalid multipart request with 0 mime parts.

I have done some searching and couldn't find anything so any help would be appreciated. Cheers in advance.

Gavin How
  • 95
  • 8
  • Will this information be useful for you? https://stackoverflow.com/questions/48492592/google-drive-sdk-with-node-js-googleapis-package-throws-error-invalid-multipart#comment83978644_48492592 – Tanaike Jan 30 '18 at 21:57
  • Sorry I didn't get back to you sooner. Yes this did help thank you :) – Gavin How Feb 08 '18 at 02:09
  • No problem. I'm glad your problem was solved. – Tanaike Feb 08 '18 at 02:22

3 Answers3

1

I'm the current maintainer of both google-auth-library and googleapis. Please, please make sure that you do not install your own version of google-auth-library along side googleapis. googleapis comes with a compatible version of google-auth-library built in. If you try to install your own version - it could break in weird, unpredictable ways.

The right thing to do here is to delete google-auth-library from your package.json, run npm install, and then use google.auth.OAuth2 for your requests. Hope this helps!

Justin Beckwith
  • 7,686
  • 1
  • 33
  • 55
0

The samples in the docs https://developers.google.com/drive/v3/web/manage-uploads appear to have been broken since version 25 of the googleapis package.

Reverting to googleapis@24.0.0 will resolve the problem until either the documentation or later package code is fixed.

Paul Lucas
  • 1,302
  • 1
  • 12
  • 18
0

I solved this problem by upgrading google-auth-library to latest version (1.3.2 at this moment).

In the official quickstart, it specifies to install the library like this:

npm install google-auth-library@0.* --save

Just do it like this to install the latest:

npm install --save google-auth-library

Notice that this upgrade has some breaking changes, so you need to upgrade your code of authorization like specified here

U-like
  • 1
  • 1