Awesome Node
Published in

Awesome Node

Upload images to google cloud storage using multer in node.js in 10 minutes.

File upload to GCP using multer

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.

Step1:

Initialize the new node.js app using the below command

Step2:

Install express, multer, multer-google-storage npm packages using below command

Step3:

Download the key file from your Google Cloud Platform account using the below steps.

  1. Go to your GCP console or here.
  2. Choose the project which you have created.
  3. Then navigate to IAM and Admin option in the sidebar and select Service Accounts options.
  4. Then click on the More icon at the end of your project and select Create Key.
  5. Select as JSON click create. This will create the key and the JSON file will be downloaded in the browser.

Step4:

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.

Final Step:

Now try calling the upload route and see the file that gets uploaded to the Storage engine in the GCP.

GitHub Repo:

This article is made with ❤️. Please do let me know if you need any specific content.

--

--

Node js core, Snippets, Tricks, and more.

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