简体   繁体   English

通过Javascript API将文件上传到Google云端硬盘时,如何设置权限?

[英]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.

相关问题 Google Drive API在Javascript中将文件上传到团队驱动器 - Google Drive API uploading a file to team drive in Javascript 使用Javascript将文件权限更改为Google云端硬盘 - Change file permissions to Google Drive with Javascript 批量插入权限API和Java Drive中的Google Drive API - Batch insert permissions API with Google Drive API in Javascript google drive sdk - 如何通过 JavaScript 上传一个简单的文件 - google drive sdk - How to upload a simple file through JavaScript 显示通过Google Drive Viewer通过Google Drive API创建的文件 - Displaying a file created through Google Drive API with the Google Drive Viewer 使用 Google Drive API Node js 上传文件时文件名是“无标题” - Filename is 'Untitled' when uploading a file using Google Drive API Node js Google Drive API V3:为域创建文件权限 - Google Drive API V3: Creating file permissions for a domain 上载文件时,Google Drive API返回403 - Google Drive API returns 403 while uploading a file 通过 Google Drive API 通过简单上传上传文件 (uploadType=media) - Uploading file via Google Drive API with simple upload (uploadType=media) 使用javascript(无html格式)以编程方式将文件上传到Google云端硬盘 - Programatically uploading a file to Google Drive using javascript (no html form)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM