2017-07-16 49 views
0

我無法在NodeJs應用程序中重命名Google Drive中的文件。我正在使用:無法使用nodeJs庫重命名Google Drive文件

  • googleapi nodeJs library v。20.1.0
  • 節點訴8.1.4

該應用程序正在處理細文件的請求,這是能夠複製文件。但是,更新它們時,新的name從不應用。

我確實得到了作爲文件資源的響應,這將需要the request was successful

我這樣做:

const google = require('googleapis'); 
let googleService = google.drive('v3'); 

let params = { 
    auth: testedAndValidOAuth, 
    fileId: validFileId, 
    uploadType: 'multipart', 
    name: "some name 2" 
}; 

googleService.files.update(params, (err, response) => console.log(response)); 

因爲我已經試過,沒有它,所有的可用選項屬性uploadTyperesumablemultipartmedia。當試圖media我得到了以下錯誤:

Error: The API returned an error: Error: Uploads must be sent to the upload URL. Re-send this request to https://www.googleapis.com/upload/drive/v3/files/xxxfileIdxxx?uploadType=media&name=some+name+2 

我試圖手動編輯在圖書館的鏈接和錯誤走開了,但不幸的是名稱沒有改變。

尋找在圖書館我已經注意到,name參數是沒有提到:

@param {object} params Parameters for request 
@param {string=} params.addParents A comma-separated list of parent IDs to add. 
@param {string} params.fileId The ID of the file. 
@param {boolean=} params.keepRevisionForever Whether to set the 'keepForever' field in the new head revision. This is only applicable to files with binary content in Drive. 
@param {string=} params.ocrLanguage A language hint for OCR processing during image import (ISO 639-1 code). 
@param {string=} params.removeParents A comma-separated list of parent IDs to remove. 
@param {boolean=} params.supportsTeamDrives Whether the requesting application supports Team Drives. 
@param {boolean=} params.useContentAsIndexableText Whether to use the uploaded content as indexable text. 
@param {object} params.resource Media resource metadata 
@param {object} params.media Media object 
@param {string} params.media.mimeType Media mime-type 
@param {string|object} params.media.body Media body contents 
@param {object} [options] Optionally override request options, such as `url`, `method`, and `encoding`. 
@param {callback} callback The callback that handles the response. 

所以我在想,我是不是做錯了什麼,這是預期的,這意味着我們不能編輯文件名,還是在圖書館的錯誤?

回答

0

嘗試在params.media.body設置你的新名字,比如

params.resource = {name: "newname"} 

修正爲根據註釋

+0

差不多!原來它必須通過'params.resource = {name:「newname」}'來設置。我必須補充說,這個文檔對此很模糊......如果你能更新答案,我會接受它:-) – ghego1

+0

同意文檔是可怕的。我認爲這些庫是自動生成的,或者至少對所有Google服務都是通用的,因此通常缺乏文檔和行爲 – pinoyyid

相關問題