简体   繁体   中英

Creating a new folder Google Drive API

I am trying to create a new folder in a shared drive through the Google Drive API. It keeps coming back with an error

Error: Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream at createError (C:\Users\SSC05\Desktop\project\PID\PID2\node_modules\axios\lib\core\createError.js:16) at dispatchHttpRequest (C:\Users\SSC05\Desktop\project\PID\PID2\node_modules\axios\lib\adapters\http.js:48) at new Promise () at Object.httpAdapter [as adapter] (C:\Users\SSC05\Desktop\project\PID\PID2\node_modules\axios\lib\adapters\http.js:20) at Gaxios. (C:\Users\SSC05\Desktop\project\PID\PID2\node_modules\gaxios\build\src\gaxios.js:65) at Generator.next () at C:\Users\SSC05\Desktop\project\PID\PID2\node_modules\gaxios\build\src\gaxios.js:19 at new Promise () at __awaiter (C:\Users\SSC05\Desktop\project\PID\PID2\node_modules\gaxios\build\src\gaxios.js:15) at Gaxios.request (C:\Users\SSC05\Desktop\project\PID\PID2\node_modules\gaxios\build\src\gaxios.js:60)

If I try to remedy that by doing fileMetaData.toString() I end up with an untitled file NOT in the shared drive. I can upload files just fine, so I know it's not a problem with the authorization. I am using the code given in the documentation. It is as follows...

function createFolder(auth) {
  const drive = google.drive({version: 'v3', auth});
  var fileMetadata = {
    'name': loadLog().name,  //A function that pulls a name from a login file
    'parents': [parentFileID],
    'mimeType': 'application/vnd.google-apps.folder'
  };
  drive.files.create({
    resource: fileMetadata,
    fields: 'id'
  }, function (err, file) {
    if (err) {
      // Handle error
      console.error(err);
    } else {
      console.log('Folder Id: ', file.id);
    }
  });
}

I came across this an answer where my google drive API service call had to pass this argument:

 supportsAllDrives=True

before my API call could access or interact with a shared drive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM