简体   繁体   中英

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). 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. 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).

  • 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).

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? Can I access them using a UI similar to the one of my own Google Drive account?

  • 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.

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? Can I access them using a UI similar to the one of my own Google Drive account?

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. 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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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