0

I'm trying this way:

var oauth2Client = new OAuth2(GDRIVE_CLIENT_ID, GDRIVE_CLIENT_SECRET, GDRIVE_REDIRECT_URI);

oauth2Client.setCredentials({
    access_token: some_valid_access_token
});

drive.files.insert({
    auth: oauth2Client,
    resource: {
        mimeType: 'application/vnd.google-apps.folder',
        title: 'my new folder'
    }
},function(err,response){
    if(err){
        console.log('error at gdrive creat folder: ' + util.inspect(err));
    }else{
        console.log('create response: ' + util.inspect(response));
    }
});

And getting an error:

You cannot upload content to files of type application/vnd.google-apps.folder

What's the correct way of doing this?

shaharsol
  • 991
  • 2
  • 10
  • 31
  • What scope are you using? Also check this link http://stackoverflow.com/questions/11280381/google-drive-api-javascript-insert-file/11361392#11361392 – SGC Mar 10 '15 at 16:52
  • This seems to be working now, at least for me with version 2.1.1 of googleapis – iss42 Jul 13 '15 at 18:19

1 Answers1

0

The error message means that you (or the library on your behalf) is trying to upload content. This makes sense for regular files, but not for folders which have no content.

So either:-

  • You're not using the library correctly and there is a content-less insert you should be using
  • It's a bug in the library

I would suggest raise an issue on the GitHub project https://github.com/google/google-api-nodejs-client and update this question with whatever response you get.

If it's holding you up, just replace the library call with a really simple POST to the Drive endpoint with your "resource" as the POST body. You might find it's so easy that you throw the library away and do it all yourself.

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • You're right about the simple POST request. Did it now and it worked in a minute... It's just that I do prefer to use an official module if provided. – shaharsol Mar 11 '15 at 09:35
  • ymv, there is nothing unofficial about using the REST API directly and you won't have anywhere near the support problems that you will using a library. – pinoyyid Mar 11 '15 at 13:50