我想从Firebase存储上传和下载图片,并在RecyclerView
中显示。我可以一次上传和下载一张图片,但我不能使用多张图片。
我该怎么做?
答案 0 :(得分:1)
目前,没有可用的API来处理从Firebase存储上传或下载多个文件。
检查以下解决方法:
答案 1 :(得分:1)
private void uploadMultipleFile(final int index){
Uri resultUri=Uri.fromFile(new File(errorImageStoredPaths.get(index)));
StorageReference riversRef = storageReference.child("images/"+resultUri.getLastPathSegment());
UploadTask uploadTask = riversRef.putFile(resultUri);
uploadTask.addOnFailureListener(exception -> {
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(@NonNull UploadTask.TaskSnapshot snapshot) {
showLog("Uploading...screens "+index);
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
showLog("Upload screen success");
riversRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
uploadedImages.add(uri.toString());
}
});
if((errorImageStoredPaths.size() - 1) != index){
uploadMultipleFile(index+1);
}else {
showLog("All upload over");
uploadToFireStore();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
showLog("Upload failed");
return;
}
});
}