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<String> 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<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(final UploadTask.TaskSnapshot taskSnapshot) {
fileRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@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());
}
});
}
Currently there's no bulk or batched upload/download to/from Firebase Storage--I think there are too many question here: would we zip the files up and store them that way, would we returned a zipped bundle, etc. Would we just return an array of download URLs, or appropriate data?
Our solution to the problem of listing and downloading multiple files is to upload them individually and store the URLs in another database (say the Firebase Realtime Database), which you can then sync and use to download each file individually (or you store the download files and use a tool like SDWebImage
to download or cache the appropriate URLs).
See https://www.youtube.com/watch?v=xAsvwy1-oxE&feature=youtu.be for an example of how we did this.