Creating a new folder Google Drive API

大憨熊 提交于 2021-01-29 09:44:18

问题


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);
    }
  });
}

来源:https://stackoverflow.com/questions/59725503/creating-a-new-folder-google-drive-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!