Im trying to update the metadata in Google Cloud Storage with Reactjs. I tried the exact code in this link How to change file's metadata in Google Cloud Storage with Node.js and it wont work on my end.
I also tried to import the ff:
import {Storage} from '@google-cloud/storage'
These are the error messages I am getting:
(1)
GET http://metadata.google.internal./computeMetadata/v1/instance net::ERR_NAME_NOT_RESOLVED
(2)
Uncaught (in promise) TypeError: Unexpected error determining execution environment:process.emitWarning is not a function
Here is my code
const storage = new Storage();
const file = storage
.bucket(bucketName)
.file(filename)
// Get the file's metadata
const [metadata] = await file.getMetadata()
// update metadata
file.setMetadata(metadata.metadata.example='updated')
The @google-cloud/storage package is meant to be used on server side and not a web app. You can use a Cloud Function that'll update the metadata based on the data from client. For example:
const functions = require('@google-cloud/functions-framework');
functions.http('updateMetadata', async (req, res) => {
const { metadata, filename } = req.body;
const file = storage
.bucket(bucketName)
.file(filename)
// update metadata
res.json({ message: "File updated" })
});
If you are using Firebase Storage, then you can also Firebase Client SDK to update metadata from client side.