Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get URLs of all images stored in firebase in Android?

I am doing this Android Project in which i want help in retrieving all the URLs which are stored in Firebase Storage and display them all in imageview. The Problem with the given code is that it only fetches one download url.In what way can i get all the URLs for all the images stored in Firebase. In short: There is one activity in which I am saving the images to firebase and in other i want to retrieve all the images in Imageview.In what way i can do it ? Thanks

if(requestCode== GALLERY_INTENT && resultCode== RESULT_OK)
    {
          mProgress.setMessage("Uploading....");
          mProgress.show();
          Uri uri =data.getData();
        StorageReference filepath = mStorage.child("Photos").child(uri.getLastPathSegment());
        filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                mProgress.dismiss();
                Uri downloadUri = taskSnapshot.getDownloadUrl();

                Picasso.with(MainActivity.this).load(downloadUri).fit().centerCrop().into(mImageView);
                Toast.makeText(MainActivity.this,"Upload done",Toast.LENGTH_LONG).show();
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(MainActivity.this,"Upload  failed",Toast.LENGTH_LONG).show();
            }
        });
    }
like image 910
Rohit Avatar asked Oct 30 '22 07:10

Rohit


1 Answers

I don't think there is an API to fetch all files stored in firebase storage. When i was saving files , i used to store the file metadata including the file name, download url etc in the real time database.

So when i had to fetch all the files from the storage, i would use the database.

Edit :

Here is how i did it.

UploadTask uploadTask = storageRef.putBytes(data,storageMetadata);
    uploadTask.addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {

        }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
             //Save to database using
         //taskSnapshot.getMetadata().getCustomMetadata(StringKeys.SOME_KEY);
        }
    }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {

        }
    });
like image 76
Dishonered Avatar answered Nov 15 '22 07:11

Dishonered