Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refFromURL() is not working in local? #3715

Closed
binajmen opened this issue Aug 30, 2021 · 1 comment · Fixed by firebase/firebase-js-sdk#5453
Closed

refFromURL() is not working in local? #3715

binajmen opened this issue Aug 30, 2021 · 1 comment · Fixed by firebase/firebase-js-sdk#5453
Assignees

Comments

@binajmen
Copy link

binajmen commented Aug 30, 2021

Environment info

firebase-tools: 9.16.5

Platform: macOS

Test case

import firebase from 'firebase/app'
import 'firebase/storage'

if (!firebase.apps.length) {
  firebase.initializeApp({ 
    ... 
  })
}

if (process.env.NODE_ENV === "development") {
  firebase.firestore().useEmulator('localhost', 8080)
  firebase.app().functions('europe-west1').useEmulator('localhost', 5001)
  firebase.auth().useEmulator("http://localhost:9099")
  firebase.storage().useEmulator("localhost", 9199)
}


function deleteImage(imageUrl: string) {
  let urlRef = firebase.storage().refFromURL(imageUrl)
  return urlRef.delete().catch((error) => console.error(error))
}

const imageUrl = "http://localhost:9199/v0/b/XXX.appspot.com/o/images%2Fdemo%2FHWEGgAPDSZrtMzbil2MwM.image%2Fjpeg?alt=media&token=a7f798ee-056a-4f03-a7bf-8453b71077e6"
deleteImage(imageUrl)
// storage.rules
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /images/{id}/{allPaths=**} {
    	allow read, write: if true;
    }
  }
}

Steps to reproduce

See test case above.

Expected behavior

Deleting the image based on the URL provided without error (same code snippet work in non-dev environment).

Actual behavior

I get the following error:

Uncaught FirebaseError: Firebase Storage: refFromUrl() expected a valid full URL but got an invalid one. (storage/invalid-argument)

@abeisgoat
Copy link
Contributor

I believe this is an SDK bug related to the makeFromUrl function which seems to explicitly match regex against https which would fail against our http endpoints. I've alerted the SDK team and will report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants