Streaming Images & Videos to Google Cloud Storage with Node.js, Express, and Multer

nickparsons profile image Nick Parsons Originally published at hackernoon.com on ・2 min read

The Problem 😒

I was tasked with transitioning code that's primary focus was to upload high-resolution images and large video files. It had to be highly reliable and more importantly, no longer live on AWS S3. I’m not going to get into the details of S3 vs. other storage providers, but I will say that Google’s infrastructure was extremely pleasing to work me when I chose to use Cloud Storage — a beautiful UI, amazing file explorer, and dozens of options that actually make sense (to me) opposed to S3.

One problem… Google has almost zero examples for uploading images that are NOT on disk to Cloud Storage. And, if they do have them, they appeared to be way out of date for my liking. After a giant headache and hours of researching StackOverflow, looking at the SDKs source code, etc., I can now say that I’ve accomplished the task… I can finally upload images using Express.js and Multer, and I’m happy to share the code that makes it all work.

Requirements 📜

  1. Upload any media file (audio, video, image, etc.)
  2. Custom UUID for the name
  3. Append proper extension to end
  4. Get MIME type to pass to Google Cloud Storage
  5. Set object ACL to “ public” so that we can view in the browser

Solution 🚨

Express, Multer, and the Google Cloud Storage package for Node.js. See below for code examples:

1. Route File 🚓

2. Controller 🚂

3. Config 🛠

That’s it! 👏

Pretty simple, right? If you have any questions about your implementation, drop them in the comments below or hit me up on Twitter. I’m always happy to help!

Posted on by:

nickparsons profile

Nick Parsons


Full Stack Developer 🤓 Director of Developer Marketing at Stream 👍Technical Writer 🖋


markdown guide

Help me i want to store the files in to specifc folders.


And what about to stream from Gcloud storage to the frontend?


he did just the first part which is saving the image on google cloud storage, the second part ,hypothetically he suppose to be saving the path of the image in the database, so when he does fetch the images he gets the list of paths and then assign each one of them to an img tag.


Why do we need to store extension?