• 4

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I am unable to delete image by 'getreferencefromUrl' or by accessing storage childs because i get the error on failurelistener

User does not have permission to access this object.

I have tried fixing storage and tried different methods to access the file to delete but it is just not working.

I am currently using:

StorageReference photoRef = mFirebaseStorage.getReferenceFromUrl(mImageUrl);

    photoRef.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
        public void onSuccess(Void aVoid) {
            Log.d(TAG, "onSuccess: deleted file");
        }).addOnFailureListener(new OnFailureListener() {
        public void onFailure(@NonNull Exception e) {
            Log.d(TAG, "onFailure: did not delete file: " e.getmessage());

My Storage rules look like:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null && request.resource.size < 500 * 1024;

The image is not getting deleted even if i am using the download url or the path url.

This is because when deleting an item the there will be no resource item in the request so that condition will fail.

You should either fine tune the writing process as follows

match /{allPaths=**} {
  allow write: if request.auth != null && request.resource.size < 500 * 1024;
  allow delete: if request.auth != null;
  allow read: if request.auth != null && request.resource.size < 500 * 1024;

or you can do it in one line using

match /{allPaths=**} {
  allow write,read: if request.auth.uid != null && 
                  (request.resource.size < 500 * 1024 || request.method == 'delete');

Additionally you should use firebase rules simulator to test your rules

  • 1
Reply Report