I have a react app which shows some image stored in firebase storage. Now after doing some changes in some data related to it, I want to copy this image from one folder to another in the same bucket. I have tried using @firebase/storage to do this but it's giving me TypeError: Unexpected error determining execution environment: Failed to fetch and after some changes from here and there TypeError: fs.createReadStream is not a function when I am not even using fs explicitly.
const copyImage = async (eventId, imageUrl) => {
const srcBucketName = 'gs://some-random.appspot.com'
console.log("srcBucketName :", srcBucketName);
const destBucketName = 'gs://some-random.appspot.com'
console.log("destBucketName :", destBucketName);
const imageExtension = imageUrl.split('?')[0].split('.')[5]
const srcFilename = `folder1/${eventId}.${imageExtension}`
console.log("Filename:", srcFilename);
const destFilename = `folder2/${eventId}.${imageExtension}`
await storage
.bucket(srcBucketName)
.file(srcFilename)
.copy(storage.bucket(destBucketName).file(destFilename))
console.log(
`gs://${srcBucketName}/${srcFilename} copied to gs://${destBucketName}/${destFilename}.`
)
return 'Successful'
}
and
async copyFile (imageURL, dest = 'folder2') {
const bucketName = 'gs://some-random.appspot.com';
let link = imageURL.split('?')[0];
let location = link.split(/[/]+/g);
dest = `${ dest }/${ location[location.length - 1] }`;
let src = location.slice(4,).join('/');
let file = await storage.bucket(bucketName).file(src).copy(storage.bucket(bucketName).file(dest));
return 'Transfered image'
}