3
votes

I am looking for a solution on the mentioned issues below. I would be grateful if someone could help us on this.

UPLOADING FILES DIRECTLY ON GOOGLE DRIVE SERVICE ACCOUNT FROM BROWSER WITHOUT USER AUTHENTICATION.

  1. We would like to use our Google Drive Service Account as a storage instead of our Web Server disk space.

  2. We are currently using DropzoneJS and Custom JS to upload files directly to our Web Server.

  3. After that we are using Google Drive PHP SDK to upload those files on our Google Drive Service Account using Google Drive API.

  4. Looking for Solution: We would like our users to upload files directly to our Google Drive Service Account without authenticating using their own Google account.

Is there a way for our users so they can upload files directly to our Google Drive Service Account by implementing JavaScript.

Looking forward to hearing from the helping genius.

1
It's certainly possible, and not very difficult. You simply need to embed your Service Account credentials in your JavaScript and request an Access Token. However, be very aware that this is a major security problem since as well as being able to upload, they will be able to modify/delete existing files.pinoyyid
@pinoyyid I think there you can set that permission setting in Drive share folder settings. Set the users to "view" instead of "edit". Your choice.noogui
@noogul He isn't sharing a folder, and he wants to upload files, so your suggestion won't work.pinoyyid
@pinoyyid, by "sharing" I meant allowing other people to upload to the Drive folder aside from the real owner ; )noogui
@noogul that's not what the OP wants to dopinoyyid

1 Answers

1
votes

Yes, by using Google Service Accounts you've just mentioned. Following Google service account guide you'll need to Setup a Service Account in Google Developer Console first.

  1. Sign-in to Google API Console.
  2. Create new project or use an existing one.
  3. Enable Google Drive API
  4. ClicK "Credentials" and "Create new oAuthClientID".
  5. Select "Service account" and create new Client ID.
  6. You will choose be asked to download your private key in JSON or P12 format.
  7. After private key download, a password for accessing it will be shown in pop-up. Make sure you dont forget it.
  8. Keep the private key in an accessible location, you'll be needing it later for your app.
  9. After that you will see "Client ID" and "Email address" for your application.
  10. Go to you Google Drive. Create some folder, and open "Sharing settings" for it.
  11. Add your service email to the list of allowed users and allow it to edit the contents of that folder.
  12. Remember your Drive folder ID like 0Bzgk4zccLwI7nXpRNG1yeDNxrYPU from drive.google.com/drive/folders/0Bzgk4zccLwI7nXpRNG1yeDNxrYPU.

After the setup, it's time to prepare making authorized API calls using JWT. Additional info that might help with the guide is a relevant post found here.