5

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.

Sirion
  • 804
  • 1
  • 11
  • 33
  • Can you clarify if this is using a Service Account or regular account? Be aware that most of the examples you will find are for the use case that a user wants to save files to his own account. Your use case is different, so you'll need to adjust the auth accordingly. – pinoyyid Feb 17 '17 at 23:22
  • I'm aware of the difference, I'm using a service account as written in the link for server to server application. – Sirion Feb 17 '17 at 23:46
  • I meant are you storing the files in a service account vs using a service account merely to proxy access to the shared folder of a regular account? – pinoyyid Feb 18 '17 at 15:50
  • Sorry, I don't understand this question (possibly because I'm not completely aware of what I've done exactly inside developer console as I say in my 'related questions'). More or less this is what I've done: create a project with this [link][https://console.developers.google.com/start/api?id=drive], enable Google Drive API in the Dashboard and then create a service account and the related json key file that I use to authorize my request to Google Drive. Therefore I think I'm storing the files in a service account (unrelated to my own account). – Sirion Feb 18 '17 at 21:38
  • Then yes you are storing the files in a Service Account. Sometimes people use a Service Account to write to the shared folder of a regular account. – pinoyyid Feb 19 '17 at 00:43

1 Answers1

1

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.

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • See instructions here: https://stackoverflow.com/questions/23382342/google-drive-access-for-service-account – nak Jul 19 '22 at 16:23