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();
}
});
}
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) {
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With