'getting No such object when trying to setMetaData in Google Cloud Storage

I'm trying to set metadata to an object like below

const id = shortid.generate();
  const docRef = this.collection.doc(id);
  const key = `${req.name}-${id}.${req.contentType.split('/')[1]}`;
  const isPrivate = req.isPrivate;
  const data = {
    isPrivate,
    key,
  };

  t.create(docRef, data);

  const options = {
    version: 'v4',
    action: 'write',
    expires: Date.now() + 60 * 60 * 1000, // 1hr
    contentType: req.contentType,
  };

  const bucket = this.buckets[isPrivate];
  console.log(`Minting url for bucket: ${bucket}`);
  
  const file = this.storage.bucket(bucket).file(key);
  const [url] = await file.getSignedUrl(options);
  file.setMetadata({
    alt: 'DDMON',
  });

I'm following this official documentation. FYI, I'm uploading using a signed URL. But getting No such object: bucket-name/file-name.jpeg error when trying to set metadata.

This is how I'm uploading image using signed url, here image is a Blob.

await axiosInstance.put(signedUrl, image, {
  headers: {
    'Content-Type': contentType,
  },
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source