React-native-firebase: v6 Storage refFromUrl does not work correctly

Created on 20 Oct 2019  ·  17Comments  ·  Source: invertase/react-native-firebase


Issue



Describe your issue here

v6 refFromURL does not work on the url below. v5 worked without problems.

firebase.storage().refFromURL(https://firebasestorage.googleapis.com/v0/b/<project-name>.appspot.com/o/<image-path>)

In v6 it throws an error that object was not found even though it exists. I was able to delete the file when using .ref(path).delete(). I don't think that the stack trace is really useful, but here it is.

code:"storage/object-not-found"
jsStack:"Error↵    at Object.delete (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:97535:23)↵    at StorageReference._delete (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:106533:43)↵    at _removeProfilePic$ (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:348611:59)↵    at tryCatch (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:5488:19)↵    at Generator.invoke [as _invoke] (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:5663:24)↵    at Generator.prototype.(anonymous function) [as next] (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:5531:23)↵    at tryCatch (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:5488:19)↵    at invoke (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:5564:22)↵    at blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:5594:13↵    at tryCallTwo (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:49272:7)"
message: "[storage/object-not-found] No object exists at the desired reference."
namespace: "storage"
nativeErrorCode: null
nativeErrorMessage: null
stack: "NativeFirebaseError: [storage/object-not-found] No object exists at the desired reference.↵    at StorageReference._delete (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:106533:43)↵    at _removeProfilePic$ (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:348611:59)↵    at tryCatch (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:5488:19)↵    at Generator.invoke [as _invoke] (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:5663:24)↵    at Generator.prototype.(anonymous function) [as next] (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:5531:23)↵    at tryCatch (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:5488:19)↵    at invoke (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:5564:22)↵    at blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:5594:13↵    at tryCallTwo (blob:file:///06ce93ab-5900-4f65-9a07-f6d7415cdc5e:49272:7)"


Project Files






iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like:

# N/A
#### `AppDelegate.m`:
// N/A


Android

Click To Expand

#### Have you converted to AndroidX? - [ x ] my application is an AndroidX application? - [ x ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ x ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`:

// N/A
#### `android/app/build.gradle`:
// N/A
#### `android/settings.gradle`:
// N/A
#### `MainApplication.java`:
// N/A
#### `AndroidManifest.xml`:
<!-- N/A -->


Environment

Click To Expand

**`react-native info` output:**

 OUTPUT GOES HERE
- **Platform that you're experiencing the issue on**: - [ ] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [ x ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - 6.0.2 - **`Firebase` module(s) you're using that has the issue:** - @react-native-firebase/storage - **Are you using `TypeScript`?** - N




Think react-native-firebase is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]

Bug Storage >= 6

Most helpful comment

I am having the exact same issue when using refFromURL. And following temporary solution worked like a charm.

const fileRefFromUrl = storage().refFromURL("https://<pathtoyourfile> ");
storage().ref(fileRefFromUrl .fullPath).delete()

However, this is a workaround. This bug needs to be fixed.

All 17 comments

Could you try the URL shown in the Firebase console, e.g:

image

The tests also show this working: https://github.com/invertase/react-native-firebase/blob/master/packages/storage/e2e/storage.e2e.js#L39

Hello 👋, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

I'm having a similar issue with the https URL. The gs:// URL works as expected, but if we try to use the https:// version the library thinks that it doesn't exist. Also, if there are any spaces in the URL it thinks that the space is the end of the file (i've tried both an encoded space %20 and a regular space ).

I can reproduce this with

  const foo= storage.refFromURL('hhttps://firebasestorage.googleapis.com/v0/b/lumiq-dev.appspot.com/o/file_example_MP3_1MG.mp3?alt=media');
  const bar = await foo.getMetadata();
  console.log(bar);

which results in

Error: [storage/object-not-found] No object exists at desired reference.

Using gs://lumiq-dev.appspot.com/file_example_MP3_1MG.mp3 works.

If you use https://firebasestorage.googleapis.com/v0/b/lumiq-dev.appspot.com/o/file%20example%20MP3%201MG.mp3?alt=media it will parse the path as just file.

Is this expected? v5 was working properly.

This is _100%_ still an issue, btw. I'm experiencing it exactly as described above.

I have no idea if it helps, but this is only happening on android.

I have this issue too.
The download url is correct, I use it for displaying the image properly, But when I do refFromUrl and try to delete the ref I'm getting storage/object-not-found

Worked well on V5.

@rkuncewicz We seem to have an issue with handling encoded urls which I will create a new issue for.

@ThomasFindlay If you can still provide an example of what url you are using then we can potentially se that for an different test case?

@sarykemmoun If you could also provide an example of this, most cases we have found so far have been encoded or incorrect urls

Seems to have something with how the ref is generated from HTTP URLs. I printed the storage ref that "doesn't exist" to console, it was missing the ".appspot.com" part of the bucket name. Normally you get something like gs://${project id}.appspot.com/${restOfPath}

As a temporary workaround I grabbed the rest of the pathname and created a new ref using storage().ref().child(${restOfPath});

Hello 👋, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.

This issue still exists with version 7.0.1. The slashes within the path are now handled correctly, but the ref is still not valid. Like @HwangPeter observed, I confirmed that valid refs have a bucket named "{BUCKET}.appspot.com" but the refs from refFromURL have a bucket named "{BUCKET}".

I am also facing the same issue, refFromURL is not working
I generated using below code,

 try {
            //console.log('Photo we need to delete ', this.state.photoURL);
            const deletePostImageFromStorageRef = Storage().refFromURL(
              this.state.photoURL,
            );
}
catch(err){
console.log("Error ",err);
}

And the error I got is
Error in deleting the post NativeFirebaseError: [storage/object-not-found] No object exists at the desired reference. at StorageReference._delete
Package.json file

 "@react-native-firebase/app": "^7.0.1",
    "@react-native-firebase/auth": "^7.0.2",
    "@react-native-firebase/firestore": "^7.1.2",
    "@react-native-firebase/functions": "^7.1.3",
    "@react-native-firebase/storage": "^7.1.2",

Any workaround for this?

Solved this issue #3820

I am having the exact same issue when using refFromURL. And following temporary solution worked like a charm.

const fileRefFromUrl = storage().refFromURL("https://<pathtoyourfile> ");
storage().ref(fileRefFromUrl .fullPath).delete()

However, this is a workaround. This bug needs to be fixed.

@enosh94 there's a PR #3775 working through review now, you can probably apply the fix locally via https://github.com/ds300/patch-package - when you say it "needs to be fixed" it implies someone should do it, with open source that's all of us and if you are suffering from this exact problem you would be a perfect test case, getting success reports for the proposed change would help it be fixed

I am having the exact same issue when using refFromURL. And following temporary solution worked like a charm.

const fileRefFromUrl = storage().refFromURL("https://<pathtoyourfile> ");
storage().ref(fileRefFromUrl .fullPath).delete()

However, this is a workaround. This bug needs to be fixed.

Thank you very much for this

Was this page helpful?
0 / 5 - 0 ratings