Google云端硬盘v3. Nodejs断点续传在错误的目录中创建无标题文件 [英] Google Drive v3. Nodejs Resumable Upload creates untitled file in wrong directory

查看:186
本文介绍了Google云端硬盘v3. Nodejs断点续传在错误的目录中创建无标题文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我已经按照云端硬盘快速入门指南中的步骤操作,并使用以下范围生成了token.json:

Hey I have followed the steps from the Drive quick start guides and generated a token.json using the following scopes:

const SCOPES = [
  'https://www.googleapis.com/auth/drive',
  'https://www.googleapis.com/auth/drive.appdata',
  'https://www.googleapis.com/auth/drive.file'
];

然后我正在运行以下代码,尝试将文件创建/上传到Google驱动器.

I am then running the following code to try and create/upload a file to google drive.

    async function testing() {
  let driveFolder = 'FOLDERID';
  let res;
  try {
    const oauth2Client = new google.auth.OAuth2(
      credentials.client_id,
      credentials.client_secret,
      credentials.redirect_uris
    );
    await oauth2Client.setCredentials({
      ...tokenInfo
    });

    console.log('=== completed drive authentication', oauth2Client);
    const drive = await google.drive({
      version: 'v3',
      auth: await oauth2Client
    });
    console.log('=== Initialised Drive API');
    res = await drive.files.create({
      parameters :{
        uploadType: 'resumable'
      },
      requestBody: {
        name: 'Testing.txt',
        mimeType: 'text/plain',
        parents: [driveFolder]
      },
      media: {
        mimeType: 'text/plain',
        body: 'Hello world!!!'
      }
    });
    console.log('=== Completed Report UPLOAD:', res);
    return;
  } catch (err) {
    console.error('ERROR: \n', err);
  }
}

请求完成但未捕获到错误,但返回的响应未定义. 最后两个日志显示以下内容

The request completes without catching an error but the response that returns is undefined. The last two logs show the following

=== completed drive authentication OAuth2Client {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  transporter: DefaultTransporter {},
  credentials:
   { access_token:
      'ACCESS TOKEN STRING',
     refresh_token:
      'REFRESH TOKEN STRING',
     scope:
      'https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.appdata',
     token_type: 'Bearer',
     expiry_date: 1551070810157 },
  certificateCache: null,
  certificateExpiry: null,
  refreshTokenPromises: Map {},
  _clientId:'CLIENT ID STRING VALUE',
  _clientSecret: 'CLIENT SECRET VALUE',
  redirectUri: [ 'REDIRECT URL', 'http://localhost' ],
  authBaseUrl: undefined,
  tokenUrl: undefined,
  eagerRefreshThresholdMillis: 300000 }
=== Initialised Drive API
=== Completed Report UPLOAD: undefined

推荐答案

您可以尝试在我的驱动器中上传的文件:

Uploaded file in my drive:

另外,请检查此 SO帖子有关更多详细信息.

Also, please check this SO post for more details.

这篇关于Google云端硬盘v3. Nodejs断点续传在错误的目录中创建无标题文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆