在Firebase中下载文件期间发生异常

时间:2017-01-24 13:33:07

标签: firebase-storage

您正在尝试使用代码

.zip存储中下载firebase文件
FirebaseStorage httpsReference = FirebaseStorage.getInstance();
StorageReference reference = httpsReference.getReferenceFromUrl(Constants.FIREBASE_ST_URL);
StorageReference referenceNew = reference.child("ImageSets").child(post.get("SetName") + ".zip");
Log.d("log_tag", "ZIP URL referenceNew : " + referenceNew.toString()); 
//**this is log result** gs://memory-matcch.appspot.com/ImageSets/set_2.zip

referenceNew.getFile(file).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
            Log.d("log_tag", "ZIP FILE onSuccess : " + Uri.fromFile(file) + "\nPath : " + file.getPath() + "\nAbsolute : " + file.getAbsolutePath());

    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {

        }
    });

这是火基规则 enter image description here

这是firebase存储 enter image description here

我收到此错误

Exception occurred during file download
java.io.IOException: open failed: ENOENT (No such file or directory)
at java.io.File.createNewFile(File.java:939)
at com.google.firebase.storage.FileDownloadTask.run(Unknown Source)
at com.google.firebase.storage.StorageTask$8.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at java.io.File.createNewFile(File.java:932)
at com.google.firebase.storage.FileDownloadTask.run(Unknown Source) 
at com.google.firebase.storage.StorageTask$8.run(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
at java.lang.Thread.run(Thread.java:818) 

我想在没有登录fire base的情况下这样做,因为用户可以在没有登录的情况下下载zip。

2 个答案:

答案 0 :(得分:1)

.getFile(file)似乎是您的问题 - 什么是file?这将zip下载到您的本地文件系统,它作为例外状态显示为“没有这样的文件或目录”。

尝试getBytes()getStream()在内存中下载,或选择要写入的有效文件。

答案 1 :(得分:0)

您只需要提供两个参数,即要在其中提供该文件的第一个文件或第二个名称 喜欢:

storageRefrence.getFile(fileDirectory, fileName).addOnCompleteListener(new ...);