user3642173 user3642173 - 2 months ago 29
Node.js Question

Attributes for image stored using Google Cloud Storage

I am using the NPM documentation for uploading an image to Google Cloud Storage'/test', upload.single('image'), function (req, res, next) {
let bucket = gcs.bucket('bucket-name');

bucket.upload(req.file.path, function(err, file) {
if (err) {
throw new Error(err);


// req.body will hold the text fields, if there were any

Is there any way I can specify a custom name and file type for the file I'm uploading? In my case it should be an image.


You can pass options to your upload method:

var options = {
  destination: 'my-image-name.jpg',
  metadata: {
    contentType: 'image/jpeg',

bucket.upload(req.file.path, options, function(err, file) {