简体   繁体   English

在Android中,从Firebase存储下载的文件存储在哪里?

[英]In Android, where does the file downloaded from Firebase storage get stored?

I uploaded a file to Firebase Storage from my project console. 我从项目控制台将文件上传到Firebase Storage。 Now, I downloaded that file from my app using the method ' Download to a local file ' as mentioned in the Firebase Storage documentation, but I am not able to find the downloaded file on my phone. 现在,我使用Firebase存储文档中提到的“ 下载到本地文件 ”方法从应用程序下载了该文件,但是我无法在手机上找到下载的文件。

Can someone tell me where does that file get downloaded to? 有人可以告诉我该文件下载到哪里吗?

    FirebaseStorage firebaseStorage = FirebaseStorage.getInstance();
    final StorageReference storageReference = firebaseStorage.getReferenceFromUrl("gs://ldq-app-d2e6b.appspot.com");

    button_down.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String fileName = new String(editText_file.getText().toString());

            StorageReference childReference = storageReference.child("Quizzes");

            StorageReference fileReference = storageReference.child("Quizzes/" + fileName + ".pdf");

            File localFile = null;

            try {
                localFile = File.createTempFile(fileName, "pdf");
            }
            catch (IOException ioe){
                Toast.makeText(getContext(), "File creation failed", Toast.LENGTH_SHORT).show();
            }

            fileReference.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
                    Toast.makeText(getContext(),"File downloaded",LENGTH_SHORT).show();
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Toast.makeText(getContext(),"Download failed. Try again!", LENGTH_SHORT).show();
                }
            });
            //Toast.makeText(getContext(),"Button working",LENGTH_SHORT).show();
        }
    });

As per Firebase Document, they are creating a temporary file for saving Image from Url. 根据Firebase文档,他们正在创建一个临时文件以保存来自网址的图片。 Link 链接

File localFile = File.createTempFile("images", "jpg");

If you want to store it on phone's internal memory or in external memory then just create a File with storage path and pass it to FileDownloadTask . 如果要将其存储在手机的内部存储器或外部存储器中,则只需创建一个具有存储路径的File并将其传递给FileDownloadTask即可

File storagePath = new File(Environment.getExternalStorageDirectory(), "directory_name");
// Create direcorty if not exists
if(!storagePath.exists()) {
    storagePath.mkdirs();
}

final File myFile = new File(storagePath,"file_name");

yourStorageRef.getFile(myFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
    // Local temp file has been created
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
    // Handle any errors
}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Firebase存储下载的文件是否存储? - file downloaded from Firebase storage get stored? 通过gradle下载的外部库在哪里存储在Android项目中? - Where does the external library, downloaded by gradle, get stored in an Android project? 如何从Firebase存储下载的文件中获取本地路径 - How to get the local path from a file downloaded from Firebase Storage 哪里下载的文件存储在android中 - Where does downloaded files stored in android 从天蓝色存储下载时,android vcs文件无法打开 - android vcs file does not open when downloaded from azure storage 从 firebase 存储下载的媒体没有出现在图库中,但出现在文件资源管理器中 - Downloaded Media from firebase storage does'not appear in gallery but appears in file explorer Firebase存储Android:如何更改下载文件的文件名? - Firebase Storage Android: How can I change the the filename of a downloaded file? 有关下载文件的元数据存储在哪里? - Where does the metadata about downloaded files get stored? Android Firebase 存储:如何在下载之前从 firebase 存储文件 url 获取文件大小? - Android Firebase Storage: How to get file size from firebase storage file url before downloading it? 内部存储实际上存储在android文件系统中的什么位置? - Where is internal storage actually stored in android file system?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM