【发布时间】:2023-04-08 02:04:01
【问题描述】:
我正在像这样成功地将图像上传到 API:
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 中。
谢谢
【问题讨论】:
-
webContentLink 可以在文件资源被检索后访问(即,使用
get)。根据[文档](developers.google.com/drive/v3/web/…,一旦你指定它就不需要授权。insert应该也可以拥有webContentLink,因为它也使用文件资源进行响应。还有其他下载文件的方法,但我认为这些不适合您的预期情况。 -
@adjuremods 感谢我体验过的输入,我必须先用
files.insert上传,然后用role=reader,type=anyone,withLink=true为该ID 设置role=reader,type=anyone,withLink=true的权限permissions.insert,然后我必须获取元数据带有files的文件,请求字段webContentLink
标签: google-drive-api