I am trying to upload a file to google storage bucket. The file will be sent to the nodejs backend route using post method and form-data. I have read google storage documents regarding uploading the files.
I am not getting the idea about how should i receive the file and assign it to filename variable so that it can be uploaded to google storage bucket. Something just like this.
const {Storage} = require('@google-cloud/storage');
// Creates a client
const storage = new Storage();
test: async (req, res, next) => {
const filename = req.body.file
// const bucketName = 'Name of a bucket, e.g. my-bucket';
// const filename = 'Local file to upload, e.g./local/path/to/file.txt';
await storage.bucket(bucketName).upload(filename, {
gzip: true,
metadata: {
cacheControl: 'public, max-age=31536000',
},
});
console.log(`${filename} uploaded to ${bucketName}.`);
}
}