Still gets the error <open failed: EACCES (Permission denied)>

Viewed 444

I have read many posts that can help me to cope with the this issue.

this is the solution of this kind of error. (just insert a line of code to androidmanifest.xml)

android:requestLegacyExternalStorage=”true”

But in my case, that insertion does not work. I am now developing a mobile app with react native. The trouble is occured when I try to put the file on firebase storage. Of course, I inserted that line of code to my androidmanifest.xml file.

<application
  android:name=”.MainApplication”
  android:label=”@string/app_name”
  android:icon=”@mipmap/ic_launcher”
  android:roundIcon=”@mipmap/ic_launcher_round”
  android:allowBackup=”false”
  android:theme=”@style/AppTheme”
  android:requestLegacyExternalStorage=”true”
>

And this is the bulidscript

buildscript {
ext {
    buildToolsVersion = “29.0.3”
    minSdkVersion = 21
    compileSdkVersion = 29
    targetSdkVersion = 29
    ndkVersion = “20.1.5948944”
    playServicesVersion = “17.0.0”
    androidMapsUtilsVersion = “2.2.3”
}
 …
}

And this is the uploading script

// uploads file
const pngRef = storage().ref(avatar/upload.png);
console.log(“pngRef”, pngRef);
await pngRef.putFile(fileUri);
const url = await storage()
  .ref(avatar/upload.png)
  .getDownloadURL();
console.log(“url”, url);

But still occurs the error.

open failed: EACCES (Permission denied)

And I got the alert on my firebase console.

Your project's Cloud Firestore database '(default)' has insecure rules

Of course, I have allowed read and write for my developement.

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if true;
    }
  }
}

ADD: This is the firestore rule. The weird thing is this projects have been working well, but suddenly appeared the error.

rules_version = '2';
  service cloud.firestore {
    match /databases/{database}/documents {
      match /{document=**} {
        allow read, write: if true;
      }
    }
   }

Is there any solution with this? Is this the firebase error? I will be happy if anyone helps me.

1 Answers

I haven't really seen rules_version line in Firebase Storage but these default rules work in rules playground so there must be something wrong on client side.

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if true;
    }
  }
}

Can you try wrapping your code in a try-catch? That might help getting some additional debugging details such as path you are trying to access.

try {
  const pngRef = storage().ref("avatar/upload.png");
  console.log(“pngRef”, pngRef);
  await pngRef.putFile(fileUri);
  const url = await storage()
    .ref("avatar/upload.png")
    .getDownloadURL();
console.log(“url”, url);
} catch (e) {
  console.log(e)
  // This should contain additional details
}

Also please try adding the ref path in quotes as I've done above. Additionally, (likely not the issue) but make sure the code is in an async function. If it's still not fixed, please add the additional details from console in your question.

Related