I have a CollectionView that I am using images from Firebase Storage to fill. I store the images under \'userId\' node. I want to check the files existence in bulk that are
I don't know if this is what you want, but i figured out an easy way of uploading multiple files into the firebase storage and get their respective download urls.
private void uploadPosts(final ArrayList mediaUris) {
StorageReference fileRef = storageRef.child("users").child(Objects.requireNonNull(mAuth.getCurrentUser()).getUid()).child("posts").child(key).child("file_" + index);
File mediaFile = new File(mediaUris.get(index));
final UploadTask uploadTask = fileRef.putFile(Uri.fromFile(mediaFile));
uploadTask.addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(final UploadTask.TaskSnapshot taskSnapshot) {
fileRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(Uri uri) {
Log.d(TAG,"URL = "+uri); //url of each file
if(index < mediaUris.size()) {
index++;
uploadPosts(mediaUris); //Recursion
}
}
});
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(), "Upload failed", Toast.LENGTH_SHORT).show();
Log.e(TAG,"Failed "+e.getCause());
}
});
}