Reputation: 1255
I am using the NPM documentation for uploading an image to Google Cloud Storage
app.post('/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);
}
console.log(file);
});
console.log(req.file);
// 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.
Upvotes: 1
Views: 59
Reputation: 3124
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) {
});
Upvotes: 2