harley_duncan
harley_duncan

Reputation: 1

How can I delete an image I have stored in Google Coud Storage Bucket in Flutter? (Not Firebase Cloud Storage)

I have the image's public link. I'm thinking of the gcloud flutter package https://pub.dev/packages/gcloud but I can't really find anything that shows how to do exactly what I'm trying. Advanced Thanks. PLEASE, I'm not talking about Firebase Cloud Storage.

Upvotes: 0

Views: 91

Answers (1)

Prajna Rai T
Prajna Rai T

Reputation: 1820

To delete a file, first create a reference to that file. Then call the delete() method on that reference, which returns a Promise that resolves, or an error if the Promise rejects.

import { getStorage, ref, deleteObject } from "firebase/storage";

const storage = getStorage();

// Create a reference to the file to delete
const desertRef = ref(storage, 'images/desert.jpg');

// Delete the file
deleteObject(desertRef).then(() => {
// File deleted successfully
}).catch((error) => {
// Uh-oh, an error occurred!
});

Upvotes: 1

Related Questions