简体   繁体   English

使用javascript从任何人上传文件到我的Google驱动器

[英]Upload file to my google drive from anyone using javascript

I am new to google api. 我是Google API的新手。 I am able to do this file upload from app script and any file which is uploaded through that script get stored to my drive only. 我能够从应用程序脚本中上传此文件,并且通过该脚本上传的任何文件都只会存储到我的驱动器中。 But how to do this using javascript. 但是如何使用javascript做到这一点。 Example on google : https://developers.google.com/drive/web/quickstart/quickstart-js shows how to do this but file gets uploaded to the same user's drive who is authorizing the app. google上的示例: https : //developers.google.com/drive/web/quickstart/quickstart-js显示了如何执行此操作,但是文件被上传到了授权该应用程序的同一用户的驱动器中。 How to restrict it to my drive only. 如何仅将其限制为我的驱动器。 Thanks 谢谢

Simple answer is you cant with JavaScript. 简单的答案是您无法使用JavaScript。 The reason being is that JavaScript works with OAuth2 this requires that you ask the user permission to access your data. 原因是JavaScript与OAuth2兼容,这需要您请求用户访问数据的权限。

If you want to have it access your drive account you would have to save the refreshtoken some place and then send that when ever the script was loaded. 如果您想让它访问您的驱动器帐户,则必须保存刷新令牌某个位置,然后在脚本加载后将其发送。 JavaScript is client sided so anyone that checked the code on the page would then have all the information they needed to do what ever they wanted with your drive account. JavaScript是客户端的,因此任何在页面上检查代码的人都将拥有他们所需的所有信息,以执行您的驱动器帐户所需的一切。 Security wise that's a bad idea. 安全方面,这是一个坏主意。

I recommend you look into using a server sided scripting language like PHP. 我建议您考虑使用像PHP这样的服务器端脚本语言。 You might want to consider a service account . 您可能需要考虑一个服务帐户 Note: everything will be owned by the service account so you will either have to give the Service account access to your Google Drive files or you will need to move your drive files to the Service account. 注意:所有内容均归服务帐户所有,因此您要么必须向服务帐户授予对Google云端硬盘文件的访问权限,要么需要将驱动器文件移至服务帐户。

If you don't want the service account to have the files you could go with normal Oauth2 save the refresh token and then store it in the server sided code there wont be as much of security risk there. 如果您不希望服务帐户拥有文件,则可以使用普通的Oauth2保存刷新令牌,然后将其存储在服务器端代码中,这样就不会有太大的安全风险。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 任何使用JavaScript将文件上传到我的Google Drive公用文件夹的人 - Anyone to upload a file to my Google Drive public folder using JavaScript 如何使用javascript将文件从Google驱动器上传到服务器 - How to upload file from google drive to server using javascript 使用JavaScript将服务器上的文件上传到Google驱动器 - Upload file on server to google drive using javascript 使用javascript SDK将文件上传到Google驱动器 - Upload file to google drive using javascript sdk 如何使用Javascript将纯文本文件上传到Google驱动器? - How to upload a plain/text file to google drive using Javascript? Javascript从网页上传文件到特定的谷歌驱动器帐户 - Javascript upload file from web page to specific google drive account 如何从 javascript 中的 Strapi 将文件上传到谷歌驱动器 - How to Upload file to google drive from strapi in javascript 从 Google Drive 下载文件并使用 NodeJS 上传到 S3 - Download file from Google Drive and upload to S3 using NodeJS 无法使用php将文件上传到Google云端硬盘 - Cannot upload file to Google Drive using php 使用 Google Apps 脚本将文件上传到我的 google 驱动器(在 GOOGLE 中没有表格) - Upload file to my google drive with Google Apps Script (NO FORM IN GOOGLE)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM