久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Google Drive API V3 (javascript) 更新文件內容

Google Drive API V3 (javascript) update file contents(Google Drive API V3 (javascript) 更新文件內容)
本文介紹了Google Drive API V3 (javascript) 更新文件內容的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想使用 Google Drive API V3 (javascript) 更新 Google 文檔的內容:

I want to update the contents of a Google doc using the Google Drive API V3 (javascript):

https://developers.google.com/drive/v3/reference/文件/更新

我能夠更新文件元數據(例如名稱),但文檔不包含實際文件內容的補丁語義.有沒有辦法在 gapi.client.drive.files.update 請求中將 JSON.stringify() 值作為參數傳遞:

I'm able to update the file metadata (such as the name) but the documentation doesn't include patch semantics for the actual file content. Is there a way to pass a JSON.stringify() value as a param in the gapi.client.drive.files.update request:

var request = gapi.client.drive.files.update({
    'fileId': fileId,
    'name' : 'Updated File Name',
    'uploadType': 'media',
    'mimeType' : 'application/vnd.google-apps.document'
  });

var fulfilledCallback = function(fulfilled) { 
    console.log("Update fulfilled!", fulfilled);
};
var rejectedCallback = function(rejected) { 
    console.log("Update rejected!", rejected);
};

request.then(fulfilledCallback, rejectedCallback)

推薦答案

有兩個問題:

  1. JavaScript 客戶端庫不支持媒體上傳.
  2. Google 文檔文件沒有原生文件格式.

您可以通過在 XHR 之上編寫自己的上傳功能來解決問題 #1.以下代碼應該適用于大多數現代網絡瀏覽器:

You can work around issue #1 by writing your own upload functionality built on top of XHR. The following code should work on most modern web browsers:

function updateFileContent(fileId, contentBlob, callback) {
  var xhr = new XMLHttpRequest();
  xhr.responseType = 'json';
  xhr.onreadystatechange = function() {
    if (xhr.readyState != XMLHttpRequest.DONE) {
      return;
    }
    callback(xhr.response);
  };
  xhr.open('PATCH', 'https://www.googleapis.com/upload/drive/v3/files/' + fileId + '?uploadType=media');
  xhr.setRequestHeader('Authorization', 'Bearer ' + gapi.auth.getToken().access_token);
  xhr.send(contentBlob);
}

要解決問題 #2,您可以向云端硬盤發送 Google Docs 可以從中導入的文件類型,例如 .txt、.docx 等.以下代碼使用上述函數使用純文本更新 Google Doc 的內容:

To work around issue #2 you can send Drive a file type that Google Docs can import from, such .txt, .docx, etc. The following code uses the function above to update the content of a Google Doc using plain text:

function run() {
  var docId = '...';
  var content = 'Hello World';
  var contentBlob = new  Blob([content], {
    'type': 'text/plain'
  });
  updateFileContent(fileId, contentBlob, function(response) {
    console.log(response);
  });
}

這篇關于Google Drive API V3 (javascript) 更新文件內容的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 久久久久久九九九九 | 亚洲午夜精品视频 | 最新国产精品视频 | 毛片免费在线 | 在线亚洲免费视频 | 一区二区视频 | 玖玖国产 | 免费av手机在线观看 | 日韩欧美视频 | 亚洲精品久久久久久国产精华液 | 四虎影院欧美 | 国产一区二区不卡 | 亚洲国产成人精品久久久国产成人一区 | 国产日韩精品一区 | 天天干天天色 | 懂色中文一区二区三区在线视频 | 美女爽到呻吟久久久久 | 国产精品久久久久久中文字 | 国产福利在线播放麻豆 | 国产乱一区二区三区视频 | 国产午夜精品一区二区三区在线观看 | www.成人久久| 久久久免费 | 国产一区二区三区日韩 | 日韩福利一区 | 国产精品一区二区免费 | 亚洲视频一区在线观看 | 一区二区三区四区视频 | 国产在线视频一区二区 | 一区二区三区四区国产 | 欧美一区二区在线观看 | 777777777亚洲妇女 | 国产精品不卡一区 | 国产精品电影在线观看 | 九九免费在线视频 | 精品国产91 | 狠狠色香婷婷久久亚洲精品 | 91久久久久久 | 久久久高清| 亚洲精品一区二区三区在线 | 亚洲国产高清高潮精品美女 |