fathi93
fathi93

Reputation: 349

Can't get image from firebase storage using glide library

i'm trying to get profile picture for every user from firebase storage within a firestore recycler adapter. i'm using the glide library to load the picture on the imageview. But i'm getting a StorageException. I always used the same code before to get picture from Firebase Storage but now i don't know what does changed.

Here's my code:

@Override
protected void onBindViewHolder(@NonNull UsersViewHolder usersViewHolder, int i, @NonNull User user) {

    FirestoreUsage.getUserPictureReference(user.getMail(), user.getGender()).child("profile_picture.jpg").getDownloadUrl()
            .addOnSuccessListener(uri -> Glide.with(context).load(uri)
                    .into(usersViewHolder.image));

    
    usersViewHolder.name.setText(user.getName());
    usersViewHolder.city.setText(user.getCity());
}


// ONE USER STORAGE REFERENCE
public static StorageReference getUserPictureReference(String userMail, String gender) {
    return getAllUsersStorageRef().child(gender).child(userMail).child("PROFILE PICTURE");
}

And here is the exception:

E/StorageException: StorageException has occurred.
Object does not exist at location.
 Code: -13010 HttpResult: 404
 E/StorageException: {  "error": {    "code": 404,    "message": "Not Found.  Could not get object",    "status": "GET_OBJECT"  }}
java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found.  Could not get object",    "status": "GET_OBJECT"  }}
    at com.google.firebase.storage.network.NetworkRequest.parseResponse(NetworkRequest.java:434)
    at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(NetworkRequest.java:451)
    at com.google.firebase.storage.network.NetworkRequest.processResponseStream(NetworkRequest.java:442)
    at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:272)
    at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:286)
    at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:70)
    at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:62)
    at com.google.firebase.storage.GetDownloadUrlTask.run(GetDownloadUrlTask.java:76)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:923)

Please help me

Upvotes: 0

Views: 634

Answers (1)

fathi93
fathi93

Reputation: 349

I have found a solution for my problem. It was about path.

Earlier, when i was registrating the profil picture of the user in firebase storage, i also saved the path of the picture in firestore.

StorageReference userProfilePicture = FirestoreUsage.getUserPictureReference(Prevalent.currentUserOnline.getMail(), gender).child("profile_picture.jpg");
        userProfilePicture.putFile(uriImageSelected).addOnSuccessListener(this, taskSnapshot -> {
            String pathImageSavedInFirebaseStorage = Objects.requireNonNull(taskSnapshot.getMetadata()).getPath();

            choiceMap.put("profile_picture", pathImageSavedInFirebaseStorage);
            Prevalent.currentUserOnline.setProfile_picture(pathImageSavedInFirebaseStorage);

Then in my adapter, i created a Storage Reference with that path and dowloaded the pic

StorageReference storageReference = FirebaseStorage.getInstance().getReference(user.getProfile_picture());
    storageReference.getDownloadUrl().addOnSuccessListener(uri -> Glide.with(context).load(uri)
                    .into(usersViewHolder.image));

Upvotes: 1

Related Questions