【问题标题】:google drive api v3 update descriptiongoogle drive api v3 更新说明
【发布时间】:2020-08-15 21:17:31
【问题描述】:

谷歌驱动 api v3

我需要更改现有对象的描述。我该如何改变这一点,而其余部分保持不变?

我是在类比python。我得到文件元数据,向其中添加“描述”行并执行更新。没有错误,描述根本没有改变

我对js不太了解,如果你能帮助我,我会很高兴的。

谢谢

function updateFile(fileId) {

  var request = gapi.client.drive.files.get({
    'fileId': fileId
  });
  request.execute(function(resp) {
    var data = resp;
    //data = data['result']
    data['description'] = "433434"
  });

  var fileMetadata = data;

  const boundary = '-------314159265358979323846';
  const delimiter = "\r\n--" + boundary + "\r\n";
  const close_delim = "\r\n--" + boundary + "--";

  var reader = new FileReader();
  reader.readAsBinaryString(fileData);
  reader.onload = function(e) {
    var contentType = fileData.type || 'application/octet-stream';
    // Updating the metadata is optional and you can instead use the value from drive.files.get.
    var base64Data = btoa(reader.result);
    var multipartRequestBody =
      delimiter +
      'Content-Type: application/json\r\n\r\n' +
      JSON.stringify(fileMetadata) +
      delimiter +
      'Content-Type: ' + contentType + '\r\n' +
      'Content-Transfer-Encoding: base64\r\n' +
      '\r\n' +
      base64Data +
      close_delim;

    var request = gapi.client.request({
      'path': '/upload/drive/v3/files/' + fileId,
      'method': 'PATCH',
      'params': {'uploadType': 'multipart', 'alt': 'json'},
      'headers': {
        'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
      },
      'body': multipartRequestBody
    });
    if (!callback) {
      callback = function(file) {
        console.log(file)
      };
    }
    request.execute(callback);
  };
}

【问题讨论】:

  • 您目前的问题是什么?
  • 问题是,我不明白该怎么做。我在pyton中实现了它,但事实证明python不适合我的任务。和 js 我非常了解
  • 感谢您的回复。不幸的是,从您的回复中,我无法理解您当前的脚本问题。我为我糟糕的英语水平道歉。
  • 我只是不知道怎么做,因为js技术不好
  • @dwmorrin 谢谢大家,我找到了我的问题。答案中写的代码

标签: javascript google-api google-drive-api google-api-js-client


【解决方案1】:

谢谢大家,我找到了我的问题。这是代码,它适用于我)

function updateFile(fileId) {
    var request = gapi.client.drive.files.get({
      'fileId': fileId
    });
    request.execute(function(resp) {
      fileMetadata = resp;
      fileMetadata['description'] = "new_description";
      delete fileMetadata.id;
      var request = gapi.client.request({
        'path': '/drive/v3/files/' + fileId,
        'method': 'PATCH',
        'body': fileMetadata});
      request.execute(function(resp) {
      });
    })
  }

【讨论】:

    猜你喜欢
    • 2023-03-06
    • 2019-11-08
    • 1970-01-01
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多