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

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

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

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

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

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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store