[英]How to set permissions when uploading a file to Google Drive through the Javascript API?
I'm currently using the Google Drive Javascript API to upload files to a user's Google Drive from their computer and simultaneously post a link to that Drive file. 我目前正在使用Google Drive Javascript API从用户的计算机上将文件上传到用户的Google Drive,同时发布指向该Drive文件的链接。
This is working quite well, except that by default the file uploads with only the user who uploaded the file having permission to view it. 这非常有效,除了默认情况下,该文件仅在上传文件的用户有权查看的情况下上传。
Therefore, what I would like to do is change the permission to "Anyone with a Link" to view it. 因此,我想做的是将权限更改为“任何有链接的人”以查看它。
https://developers.google.com/drive/web/quickstart/quickstart-js https://developers.google.com/drive/web/quickstart/quickstart-js
This is the page that I used as a reference for the JavaScript required to upload the file to Google Drive. 这是我用作将文件上传到Google云端硬盘所需的JavaScript的参考页面。 What would I need to change here in order to change the permission of the uploaded file?
为了更改上传文件的权限,我需要在此处进行哪些更改?
Thanks in advance! 提前致谢!
As per my knowledge you can set the visibility parameter to "DEFAULT" in the request something like this: 据我所知,您可以在请求中将可见性参数设置为“ DEFAULT”,如下所示:
var request = gapi.client.request({
'path': '/upload/drive/v2/files',
'method': 'POST',
'params': {'uploadType': 'multipart', 'visibility': 'DEFAULT'},
'headers': {
'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
},
'body': multipartRequestBody});
The other way would be inserting a file to Drive and then use Permissions.insert() to insert permissions to that file by Id and add a property in the request like 'type' to 'anyone'. 另一种方法是将文件插入到云端硬盘,然后使用Permissions.insert()通过ID向该文件插入权限,并在请求中向“任何人”添加“ type”之类的属性。
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.