angularfire
angularfire copied to clipboard
Getting metadata or deleting empty folder will result 404
Version info
Angular: 14.1.3
Firebase: 9.9.3
AngularFire: 7.4.1
Other (e.g. Ionic/Cordova, Node, browser, operating system):
How to reproduce these conditions
- Create an empty folder in cloud storage
- then run below code
import { AngularFireStorage } from '@angular/fire/compat/storage';
...
constructor(private storage: AngularFireStorage) {}
....
const ref = this.storage.ref(pathToFolder);
ref.getMetadata().toPromise(); // this will result a GET request with 404 as response
ref.delete().toPromise(); // this will result a DELETE request with 404 as response
Failing test unit, Stackblitz demonstrating the problem
Steps to set up and reproduce
Sample data and security rules
Debug output
** Errors in the JavaScript console **
** Output from firebase.database().enableLogging(true);
**
** Screenshots **
Expected behavior
Actual behavior
Firebase Cloud Storage is basically the same as Google Cloud Storage, and there is no such thing as a directory in Google Cloud Storage. See https://cloud.google.com/storage/docs/objects and https://cloud.google.com/storage/docs/naming-objects for details.
@jnizet Yes I understand that, the issue is I am bale to get the ref but not able to do the operation. I tried adding trailing slash to the path, but still same
IMO seems anguarfire is removing trailing slashes from path
I am able to do delete the folder in backend using the below code, and ended up using the api to delete the folder
async deleteFolder(bucketName: string, folder: string): Promise<void> {
const bucket = this.storage.bucket(bucketName);
const [files] = await bucket.getFiles({ prefix: `${folder}/` });
await Promise.allSettled(files.map(file => file.delete({ ignoreNotFound: true })))
}
That code deletes all the objects under a prefix. It's not the same as trying to delete a folder, because folders don't exist.
@jnizet would you do me a favor and share a working code snippet that deletes a folder on cloud storage successfully?
No, because there is no such thing as a folder on cloud storage. You can't delete something that doesn't exist.
my goal is to delete this, and there is no files under it