Upload Any File Into Google Drive With Fastify and Googleapis Node Package

Dafa Pramudya
2 min readMar 30, 2020


بِسْــــــــــــــــــمِ اللهِ الرَّحْمَنِ الرَّحِيْمِ

السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ

In some of conditions we need a storage to store any file that we need to shared it to others. Especially if we have an API upload service.

In this post, we are going to create a simple upload REST API to Google Drive. In this case we will using fastify and googleapis node package.

First, you need to create project folder and initiate package.json with npm init, then install those npm package.

  1. Fastify
  2. Googleapis
  3. Fastify File Upload
  4. Streamifier

After that, prepare your snack and coffee xD

First you need to have an Google Account, then go to Google Cloud Platform, and create a new project. After that, go to IAM & Admin => Service Account, and create Service Account. At point 3 you need to Create Key first to download the private_key of your service account.

or you can doing it by click more action button at service account list.

Let’s jump to coding time…

Back to your project directory, then create a upload route at index.js/server.js (your main app)

At the permission object, i set it to: type: anyone, role: reader. Because i want to share my file to everyone, but they can only read the file.

For more information about permission, you can read here.

OK i think it’s all caught! time to test it on postman. npm start your project and open your postman/your favorite request API apps, then input your API endpoint and don’t forget to make form-data in body request then hit send button.

Open the link!

Ok that’s all. If this article was helpful, please clap and share it.

Thank you guys!

Happy Coding :D

SC: here

وَ السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ



Dafa Pramudya

Programmer, Solving Problem Addict