問題描述
此問題已成功解決.我正在編輯我的帖子以記錄我的經驗,以供后人參考.
This problem has been successfully resolved. I am editing my post to document my experience for posterity and future reference.
我有 117 個 PDF 文件(平均大小約為 238 KB)上傳到 Google 云端硬盤.我想將它們全部轉換為 Google Docs 并將它們保存在不同的 Drive 文件夾中.
I have 117 PDF files (average size ~238 KB) uploaded to Google Drive. I want to convert them all to Google Docs and keep them in a different Drive folder.
我嘗試使用 Drive.Files.insert.但是,在大多數情況下,只有 5 個文件可以通過這種方式在函數因此錯誤過早過期之前進行轉換
I attempted to convert the files using Drive.Files.insert. However, under most circumstances, only 5 files could be converted this way before the function expires prematurely with this error
超出限制:DriveApp.(第 # 行,文件代碼")
Limit Exceeded: DriveApp. (line #, file "Code")
上面引用的行是調用 insert
函數的地方.第一次調用此函數后,后續調用通常會立即失敗,并且沒有創建額外的 google doc.
where the line referenced above is when the insert
function is called. After calling this function for the first time, subsequent calls typically failed immediately with no additional google doc created.
我使用了 3 種主要方法來實現我的目標.一個是使用 Drive.Files.insert,如上所述.另外兩個涉及使用 Drive.Files.copy 并發送 一批 HTTP 請求.最后兩種方法是 Tanaike 建議的,我建議閱讀下面的答案以獲取更多信息.insert
和 copy
函數來自 Google Drive REST v2 API,而批處理多個 HTTP 請求來自 Drive REST v3.
I used 3 main ways to achieve my goal. One was using the Drive.Files.insert, as mentioned above. The other two involved using Drive.Files.copy and sending a batch of HTTP requests. These last two methods were suggested by Tanaike, and I recommend reading his answer below for more information. The insert
and copy
functions are from Google Drive REST v2 API, while batching multiple HTTP requests is from Drive REST v3.
使用 Drive.Files.insert,我遇到了處理問題具有執行限制(在上面的問題部分中進行了解釋).一種解決方案是多次運行這些功能.為此,我需要一種方法來跟蹤哪些文件被轉換.我有兩個選擇:使用電子表格和 延續令牌.因此,我有 4 種不同的方法來測試:本段中提到的兩種,批處理 HTTP 請求,并調用 Drive.Files.copy.
With Drive.Files.insert, I experienced issues dealing with execution limitations (explained in the Problem section above). One solution was to run the functions multiple times. And for that, I needed a way to keep track of which files were converted. I had two options for this: using a spreadsheet and a continuation token. Therefore, I had 4 different methods to test: the two mentioned in this paragraph, batching HTTP requests, and calling Drive.Files.copy.
因為團隊驅動器的行為不同于常規驅動器,我覺得有必要嘗試每種方法兩次,其中包含 PDF 的文件夾是常規的非團隊驅動器文件夾,另一種方法是該文件夾位于團隊驅動器下.總的來說,這意味著我有 8 個不同的測試方法.
Because team drives behave differently from regular drives, I felt it necessary to try each of those methods twice, one in which the folder containing the PDFs is a regular non-Team Drive folder and one in which that folder is under a Team Drive. In total, this means I had 8 different methods to test.
這些是我使用的確切功能.每個都使用了兩次,唯一的變化是源文件夾和目標文件夾的 ID(出于上述原因):
These are the exact functions I used. Each of these was used twice, with the only variations being the ID of the source and destination folders (for reasons stated above):
function toDocs() {
var sheet = SpreadsheetApp.openById(/* spreadsheet id*/).getSheets()[0];
var range = sheet.getRange("A2:E118");
var table = range.getValues();
var len = table.length;
var resources = {
title: null,
mimeType: MimeType.GOOGLE_DOCS,
parents: [{id: /* destination folder id *
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!