16

I want display image in imageView, that's what I'm doing: I'm using FirebaseUI to display images from FireBase Storage.

FirebaseStorage storageDisplayImg;
StorageReference storageRef;
private FirebaseAuth auth;



        storageDisplayImg=FirebaseStorage.getInstance();
        auth = FirebaseAuth.getInstance();
        FirebaseUser userConnect = auth.getCurrentUser();
        String id_user=userConnect.getUid();
        storageRef = storageDisplayImg.getReference().child(item.getChemin_image()); // return gs://mydreambook-32321.appspot.com/images/test23-03-2017_16:46:55

        if (item.getChemin_image() != null&&id_user != null) {

           Glide.with(convertView.getContext() )
                   .using(new FirebaseImageLoader())
                   .load(storageRef)
                   .into(profilePic);
            profilePic.setVisibility(View.VISIBLE);

        } else {
            profilePic.setVisibility(View.GONE);
        }

But I have this error:

StorageException has occurred.  Object does not exist at location.    Code: -13010 HttpResult: 404

Update , Image in storage FireBase

enter image description here

Amal
  • 279
  • 3
  • 5
  • 21
  • Use the Firebase Console to confirm there is an image stored at location `gs://myApp.appspot.com/images/sport23-03-2017_15:22:54` – Bob Snyder Mar 23 '17 at 16:56
  • Please check the Update @BobSnyder – Amal Mar 23 '17 at 17:19
  • 2
    Does `item.getChemin_image()` return the full string "gs://myApp.appspot.com/images/sport23-03-2017_15:22:54" or does it only return "images/sport23-03-2017_15:22:54"? If it returns the former you actually want to do `storageDisplayImg.getReferenceFromUrl(item.getChemin_image())` (which takes the full URL). – Mike McDonald Mar 23 '17 at 17:33
  • it works , thanks @MikeMcDonald – Amal Mar 23 '17 at 20:06

10 Answers10

6

I had the same problem right now and I realized that my image in storage ends with .jpg but my code is asking for the address that ends with .png. After I fixed that, it ran perfectly for me.

alibabaei12
  • 161
  • 1
  • 2
  • 9
3

You can simply show the image in two ways using Glide method. If we want to access below method, we must change the Firebase Storage Rules. Here I included my rules.

service firebase.storage {
  match /b/project-id.appspot.com/o {
    match /{allPaths=**} {
      allow write: if request.auth != null;
      // or allow write: if true;
    }
  }
} 

Method 1. Simply use the Firebase Reference

FirebaseStorage storage = FirebaseStorage.getInstance();
                StorageReference storageRef = storage.getReferenceFromUrl("gs://your-id.appspot.com");
                StorageReference pathReference = storageRef.child("images/cross.png");

                Glide.with(context)
                        .using(new FirebaseImageLoader())
                        .load(pathReference)
                        .into(Imageview)

Method 2. Firebase URL

     Glide.with(context)
             .using(new FirebaseImageLoader())
             .load("Firebase_ImageURL")
             .into(Imageview)
Thaerith
  • 697
  • 4
  • 13
sivaprakash
  • 528
  • 6
  • 15
3

hi i faced such problem two days ago. storage exception occurs normally to the projects which you created with google developer console prior to Firebase launch. so when i connected my app to existing project on Firebase it worked. to confirm whether your project accepts storage or not go to Firebase console and on left click storage if you were displayed with the file upload option there the project is capable of storage other wise not.

1

Okay i found solution when i got to know that i had to give complete path of an image

 storageReference.child("users").child(userID).child("screenshot")
                .child(imagePath).getFile(localFile)

enter image description here

And i was initially giving incomplete path

 storageReference.child("users").child(userID).child("screenshot").getFile(localFile)
              
0

I had a similar problem. I was trying to delete a file with some wrong case letters

Example: Deleting file_of_user_uidabcde.png by searching for file_of_user_uIdAbCdE.png

Rodrigo João Bertotti
  • 5,179
  • 2
  • 23
  • 34
0

You can try to wait some time between the upload of the image and the recuperation of the image. That worked in my issue like this. Wish you a good luck.

0

In my case, I am saving the complete URL in the Firebase database and get it like this: gs: //your-id.appspot.com/images/cross.png

When I do this:

StorageReference ref = FirebaseStorage().Ref().Child(urlImag);
      url = (await ref.getDownloadURL()).toString();

I am doing the following:

StorageReference ref = FirebaseStorage (gs://your-id.appspot.com/images/cross.png).ref().child ();
      url = (await ref.getDownloadURL()).toString();

This step is not necessary if you already have the full URL saved in your field.

Matt Ke
  • 3,599
  • 12
  • 30
  • 49
0

I was using different Firebase project then I created new one. When I added google-services.json and trying to add photo in storage I occured this error. When I debuggin my project I occured that my storage ref showing old url (gs://oldproject.appspot.com). I searched appspot.com in Android project and seen values.xml file. Change values.xml file content with new firebase project id and then storage works.

0

Please check rule on storage if you get 404 error:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, create: if request.auth != null;
    }
  }
}
0

I just check the type saved in my Firebase Storage.

So it automatically changed the type of my image from images/jpeg to webp.

This solution worked for me:

// Create file metadata including the content type
    StorageMetadata metadata = new StorageMetadata.Builder()
            .setContentType("image/jpeg")
            .build();


// Upload the file and metadata
    uploadTask = storageRef.child("images/mountains.jpg").putFile(file, 
    metadata);

check this https://firebase.google.com/docs/storage/android/upload-files#add_file_metadata