At InReach Ventures we contact thousands of organisations for which we often have a large number of related documents. To make collaboration between team members simple and easy we store these documents in Google Drive, using a dedicated folder for each organisation.
Sometimes, an entrepreneur will share a Google Doc with us, and we want to add it to their folder. Doing this via the Google Drive web interface is, to be polite, sub-optimal. You can add a shared document to a folder. But if you have more than a couple of dozen folders to chose from you’ll be scrolling a very long time (at which point Chrome will lock up for a few seconds before your MacBook reboots — yes, this really happened to me).
Press enter or click to view image in full size
The solution to this takes advantage of how Google Drive implements folders. On the server side, at least, folders are just a special type of file. Whether a file is contained in a given folder is controlled by a metadata property on the file, parents, which contains an array of the “folders” within which that file is contained. Importantly, it isn’t necessary to be the owner of a file to be able to add a parent to its parents metadata property. It is sufficient to have read only access to the file (it should go without saying that write access to the folder is necessary).
Get Hugo Jobling’s stories in your inbox
Join Medium for free to get updates from this writer.
Performing this action is a straightforward action via the Google Drive v3 API. Assuming you have a valid access token to authenticate your request, adding a file to a folder is a single API call.
I don’t expect my colleagues to paste JavaScript into a console every time they want to add a file to an organisation’s folder. Instead, I added some UI to our software platform to enable uploading files into an organisation’s Google Drive folder when viewing that organisation.
Press enter or click to view image in full size
Since it wasn’t much more work, I also added the ability to upload a file from the desktop to an organisation folder. This saves the need to go hunting for it in Google Drive, reducing the time and frustration spent performing that semi-frequent task.
It’s only a matter of time until an update to the Google Drive API or product breaks this workflow. Until then, it solves our use case pretty well.