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.
First, you need to create project folder and initiate package.json with npm init, then install those npm package.
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.
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
وَ السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ