如何从Firebase存储下载图像文件

时间:2019-07-17 00:54:44

标签: android firebase download firebase-storage

好的,所以我尝试的方法是.getfile()用于下载图像。它也会触发成功侦听器,但是我无法在内部存储中找到文件,不确定是否可以访问

 @Override
    public void onDownloadClick(int position) {
        Toast.makeText(this, "will try to dwonload XD" , Toast.LENGTH_LONG).show();


        Upload selectedItem= mUploads.get(position);
        final String selectedkey= selectedItem.getKey();
        StorageReference imgRef=mStorage.getReferenceFromUrl(selectedItem.getImageUrl());
try{
    File localFIle=File.createTempFile("images", "jpg");

    imgRef.getFile(localFIle).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
            Toast.makeText(ImagesActivity.this, "downloaded" , Toast.LENGTH_LONG).show();
            Log.d("file ", "filedownloaded");


        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Toast.makeText(ImagesActivity.this, "not able to download" , Toast.LENGTH_LONG).show();


        }
    });
}
    catch (Exception e)
    {

    }






    }

1 个答案:

答案 0 :(得分:0)

您似乎正在创建一个名为localFIle的File对象。如果您想知道它的路径,只需记录其字符串值。如果这不是您想要的位置,请尝试其他操作。我建议阅读the documentation on locating files on Android devices