Is it possible refFromURL()
is not working in local?
function deleteImage(imageUrl: string) {
let urlRef = firebase.storage().refFromURL(imageUrl)
return urlRef.delete().catch((error) => console.error(error))
}
When passing the following url:
http://localhost:9199/v0/b/xxx.appspot.com/o/images%2Fdemo%2FHWEGgAPDSZrtMzbil2MwM.image%2Fjpeg?alt=media&token=a7f798ee-056a-4f03-a7bf-8453b71077e6
I get the following error:
Uncaught FirebaseError: Firebase Storage: refFromUrl() expected a valid full URL but got an invalid one. (storage/invalid-argument)
For future googlers, this is a known issue that was fixed in Firebase SDK 9.0.2. See the issue for details, but as far as I can tell, the problem had to do with the URL parser not liking http
links. Normally this is fine, but the local emulator runs on localhost, and localhost will be http
for the foreseeable future.
$ npm i firebase@9.0.2
# or
$ npm i firebase@latest
Note: If you're coming from version 8.x.x or lower, there are some breaking changes. Lucky for us, there is a "compat" API that should keep your immediate code changes minimal. Here's a migration guide for you.