user3642173 user3642173 - 1 year ago 70
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.

Answer Source

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) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download