Upload images to google cloud storage using multer in node.js in 10 minutes.
In this article, we are going to use the multer to upload the images to the google cloud storage engine using node.js in 10 minutes.
Initialize the new node.js app using the below command
npm init -y
Install express, multer, multer-google-storage npm packages using below command
npm i -S express multer multer-google-storage
Download the key file from your Google Cloud Platform account using the below steps.
- Go to your GCP console or here.
- Choose the project which you have created.
- Then navigate to IAM and Admin option in the sidebar and select Service Accounts options.
- Then click on the More icon at the end of your project and select Create Key.
- Select as JSON click create. This will create the key and the JSON file will be downloaded in the browser.
Create the sample express server and the upload route as below:
Now add the multer and multer-google-storage dependencies to the upload route
bucket — Go to GCP and select the storage from the side menu. This will display all the storage buckets with their name.
projectId- This can be fetched from the downloaded key file.
Now try calling the upload route and see the file that gets uploaded to the Storage engine in the GCP.
Clone the gcp-image-upload repository Open the terminal and navigate to clonned project. Install the dependencies using…
This article is made with ❤️. Please do let me know if you need any specific content.