Firebase存储 - 在Android中上传多个图像文件

时间:2016-09-05 12:41:48

标签: android firebase firebase-storage

我想从Firebase存储上传和下载图片,并在RecyclerView中显示。我可以一次上传和下载一张图片,但我不能使用多张图片。

我该怎么做?

2 个答案:

答案 0 :(得分:1)

目前,没有可用的API来处理从Firebase存储上传或下载多个文件。

检查以下解决方法:

  1. https://stackoverflow.com/a/37337436/6523173
  2. https://stackoverflow.com/a/37849978/6523173

答案 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;
        }
    });
}