久久久久久久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 服務器時的歡迎消息)
主站蜘蛛池模板: 日日操夜夜摸 | 日韩欧美亚洲 | 91精品在线播放 | 久久久久久高潮国产精品视 | 国产精品久久久久免费 | 免费色网址 | 亚洲91av| 黄a免费网络 | 婷婷免费视频 | 在线视频一区二区三区 | 欧美精品久久一区 | 国产精品久久久久久久久久 | 精品日韩一区二区三区av动图 | 久久97精品 | 日韩精品一二三 | 亚洲a一区 | 精品久久中文 | 久久精品亚洲成在人线av网址 | 中国黄色毛片视频 | 国产99久久精品一区二区永久免费 | 91社区在线高清 | 亚洲精品中文在线观看 | 日韩美女一区二区三区在线观看 | 久久综合伊人 | 亚洲精品欧美精品 | 人人鲁人人莫人人爱精品 | 亚洲电影成人 | 亚洲在线一区 | av福利网站 | 欧美日韩精品一区 | 亚洲经典一区 | 亚洲免费在线观看视频 | 天天操天天拍 | 精品亚洲永久免费精品 | 亚洲永久 | 精品久久国产 | 蜜桃免费一区二区三区 | 亚洲欧美中文日韩在线 | 蜜月va乱码一区二区三区 | 久久久久久亚洲精品不卡 | 久久久精品一区二区三区 |