我成功上傳到API的圖像是這樣的:谷歌驅動器上傳圖片 - 數據不返回webContentLink - 直接permenant鏈接
https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart
Authorization: 'Bearer ' + token,
'Content-Type': 'multipart/form-data; boundary="' + boundary + '"'
--data: multipartRequestBody
其中multipartRequestBody
是:
{
name: 'screenshot.png',
mimeType: 'image/png',
// parents: ['0B5IwavgVGMN9ekR2dEhuaUxkZTA'] // set this to the id of a the folder you want to upload it into
};
是否有一些密鑰可以提供給我的mulitpartRequestBody
,它會告訴GDrive將其作爲公共共享文件上載並返回在webContentLink
?我可以使用src
的<img src="...">
而不限制視圖帶寬?
我試過設置writersCanShare: true
但是它仍然不會返回webContentLink
。我也嘗試加入type: 'anyone', role: 'reader'
,但那也沒用。
基本上我試圖做什麼https://drive.google.com/uc?export=view&id={fileId}
做的,但在insert
調用的API。
感謝
一旦Files資源被檢索(即使用'get'),就可以訪問webContentLink。根據[文檔](https://developers.google.com/drive/v3/web/manage-downloads#viewing_files_in_a_browser),一旦您指定了它,就不需要授權。insert應該能夠擁有'webContentLink',因爲它也使用文件資源作爲響應。還有其他方式可以下載文件,但我認爲這些文件不適用於你想要的情況。 – adjuremods
@adjuremods感謝我實驗過的輸入,並且我必須首先隨後用'files.insert'寫入,然後設置'role = reader的權限,type = anyone,withLink = true',用'permissions.insert'作爲id,然後我必須用'files'請求領域'webContentLink' – Noitidart