Google Drive API v3更新说明 [英] google drive api v3 update description

查看:79
本文介绍了Google Drive API v3更新说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

google drive api v3

google drive api v3

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

I need to change the description of an existing object. How do I change just that, leaving the rest unchanged?

我正在用python做类比.我得到了文件元数据,然后添加描述".行并执行更新.没有错误,说明根本不会改变

I am doing by analogy with python. I get the file metadata, add the "description" line to it and execute update. There are no errors, the description simply does not change

我对js不太了解,如果您能帮助我,我会很高兴.

I don't know much about js, I will be glad if you can help me.

谢谢

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

推荐答案

谢谢大家,我知道了我的问题.这是代码,对我有用)

Thank you all, I figured out my problem. Here is the code, it works for me)

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

这篇关于Google Drive API v3更新说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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