简体   繁体   English

通过Django Web应用程序将用户文件上传到Google驱动器

[英]Upload user file to google drive through django web application

I want to use Google Drive as storage for my Django project (in particular I need to store images taken by users). 我想将Google云端硬盘用作Django项目的存储空间(尤其是我需要存储用户拍摄的图像)。 What I'm trying to achieve is the following: 我正在尝试实现以下目标:

  • Users upload their images using a form. 用户使用表单上载图像。 These files must be somehow routed through Django which redirects them to Google Drive using Google Drive API. 这些文件必须以某种方式通过Django路由,而Django使用Google Drive API将它们重定向到Google Drive。 The reason I do not send the files directly from the user's browser to Google Drive is that I should store on the client side the secrey key to access Google Drive API (which, of course, must not be directly accessible by the end users). 我之所以没有将文件直接从用户浏览器发送到Google云端硬盘,是因为我应该在客户端存储用于访问Google云端硬盘API的密钥(当然,最终用户不能直接访问该密钥)。

  • Once uploaded, I must be able to display the images in a gallery on my site. 上传后,我必须能够在网站上的图库中显示图像。

So far I've read Google Drive API documentation and, in particular, I've managed to accomplish the quickstart using OAuth2 for server to server applications, see here (the quickstart covers the case where files are uploaded to user's Google Drive folder so there is an intermediate step of user authentication that I do not need; instead, I'm using a service account to authorize my api requests). 到目前为止,我已经读过谷歌云端硬盘API文档,特别是,我已经成功地完成快速入门使用的OAuth2服务器到服务器的应用程序,请参见这里 (快速启动覆盖了文件上传到用户的谷歌云端硬盘文件夹所以的情况下是我不需要的用户身份验证的中间步骤;相反,我使用服务帐户来授权我的api请求)。

SIDE QUESTIONS: 侧面问题:

  • Is there a way to access in a browsable way the list of files uploaded by the users to Google Drive through the API or the API is the only interface to them? 是否可以通过浏览方式访问用户通过API上传到Google云端硬盘的文件列表,或者API是他们的唯一界面? Can I access them using a UI similar to the one of my own Google Drive account? 我可以使用与自己的Google云端硬盘帐户类似的UI访问它们吗?

  • Also, I'm new to Google services and developer console seems to me quite a mess... I haven't understood how much disk space is available to me and how/if this storage space is related to my own Google Drive account. 另外,我是Google服务的新手,开发人员控制台对我来说似乎是一团糟...我不知道我有多少可用磁盘空间以及该存储空间如何/是否与我自己的Google云端硬盘帐户相关。

Is there a way to access in a browsable way the list of files uploaded by the users to Google Drive through the API or the API is the only interface to them? 是否可以通过浏览方式访问用户通过API上传到Google云端硬盘的文件列表,或者API是他们的唯一界面? Can I access them using a UI similar to the one of my own Google Drive account? 我可以使用与自己的Google云端硬盘帐户类似的UI访问它们吗?

The short answer is no. 最简洁的答案是不。 Service Accounts are specifically intended to be access only by the application they are "owned" by. 服务帐户专用于仅由其“拥有”的应用程序访问。 However, if this is important, you can use folder sharing, to either (1) to make the Service Account data visible in the UI of a regular account, or (2) to allow your app to write to the folder of a regular account via the shared folder. 但是,如果这很重要,则可以使用文件夹共享,以(1)使服务帐户数据在常规帐户的UI中可见,或(2)允许您的应用写入常规帐户的文件夹通过共享文件夹。 Be aware that either way, the files will consume quota on the Service Account, not the regular account. 请注意,无论哪种方式,文件都会消耗服务帐户(而不是常规帐户)上的配额。

Another option is to not use a Service Account at all, and do everything using a regular account. 另一种选择是完全不使用服务帐户,而使用常规帐户进行所有操作。

I haven't understood how much disk space is available to me and how/if this storage space is related to my own Google Drive account. 我不知道有多少可用磁盘空间以及该存储空间如何/是否与我自己的Google云端硬盘帐户相关。

The simplest approach is to use the About.get ( https://developers.google.com/drive/v3/reference/about/get ) to get your limit and used quota. 最简单的方法是使用About.get( https://developers.google.com/drive/v3/reference/about/get )来获取限制和已使用的配额。 The Service Account is an independent account and has no relationship (at least in terms of storage and access) to the regular account that you used to create it. 服务帐户是一个独立帐户,与您用来创建该帐户的常规帐户没有任何关系(至少在存储和访问方面)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM