node.js - How to fix the storage exceeded issue for Google Drive when uploading using Service Accounts -


if you're using google apps work (also called g-suite) , uploading files google drive via drive api you'll find error message looks this:

error: user's drive storage quota has been exceeded. 

read below learn why happens , how solve it.

background:

google drive api authorized using "service accounts", not regular "human users". google not have way increase 15gb limit service accounts, , there no mechanism buying additional space. once you've consumed standard space allocation you'll prevented uploading additional files.

human/regular g-suite users standard 15gb simple options increase 100gb or more mere pennies.

so how upload files against storage quota of human account rather service account can have space want? it's simple! not super documented...

solution:

this solution configure service account impersonate human account. means still authenticate drive api using service account service account authorized act on behalf of human account , storage space allocated user's quota.

prep: important. carefully review instructions here make sure service account set correctly impersonation. deviation give random errors frustrate , waste time. service account needs have dwd (domain-wide-delegation) enabled in google iam console , needs permitted access drive scope in api client access page of google admin site.

now service account set up, impersonate regular account need specify human account email address when creating jwt client.

in nodejs looks (note last parameter):

let jwtclient = new googleapi.auth.jwt( service_account_email, null, private_key, ['https://www.googleapis.com/auth/drive'], 'impersonated_user@mydomain.com');

for other languages, please refer official google documentation how impersonate user.

when drive api script uploads files owned regular user , space allocated quota. increasing trivial , can done administrator or contacting g-suite support.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -