如何从Firebase Storage中的多个文件上传获取downloadUrl?

时间:2019-08-15 01:38:07

标签: android firebase firebase-storage

我在Firebase存储中上传了多个文件,我以前上传到Firebase数据库的每个文件都可以获得DownloadUrl吗? 这里有一些代码

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK){
        if(data.getClipData() != null){
            int totalItemsSelected = data.getClipData().getItemCount();
            for(int i = 0; i < totalItemsSelected; i++){
                Uri fileUri = data.getClipData().getItemAt(i).getUri();
                String fileName = getFileName(fileUri);
                fileNameList.add(fileName);
                fileDoneList.add("uploading");
                uploadListAdapter.notifyDataSetChanged();
                StorageReference fileToUpload = mStorage.child("Images").child(fileName);
                final int finalI = i;
                fileToUpload.putFile(fileUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                        fileDoneList.remove(finalI);
                        fileDoneList.add(finalI, "done");
                        //Task<Uri> downloadUri = taskSnapshot.getStorage().getDownloadUrl();
                        //String imageUrl = downloadUri.toString();
                        //mTv10.setText(imageUrl);
                        uploadListAdapter.notifyDataSetChanged();
                    }
                });
            }
        } else if (data.getData() != null){
            Toast.makeText(addImagesActivity.this, "Selected Single File", Toast.LENGTH_SHORT).show();
        }
    }
}

0 个答案:

没有答案