angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Getting metadata or deleting empty folder will result 404

Open RezaRahmati opened this issue 1 year ago • 6 comments

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

  1. Create an empty folder in cloud storage
  2. 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 ** image

Expected behavior

Actual behavior

RezaRahmati avatar Aug 26 '22 23:08 RezaRahmati

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 avatar Sep 03 '22 17:09 jnizet

@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 })))
    }

RezaRahmati avatar Sep 05 '22 17:09 RezaRahmati

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 avatar Sep 05 '22 17:09 jnizet

@jnizet would you do me a favor and share a working code snippet that deletes a folder on cloud storage successfully?

RezaRahmati avatar Sep 05 '22 17:09 RezaRahmati

No, because there is no such thing as a folder on cloud storage. You can't delete something that doesn't exist.

jnizet avatar Sep 05 '22 18:09 jnizet

my goal is to delete this, and there is no files under it

image

RezaRahmati avatar Sep 05 '22 18:09 RezaRahmati