您正在尝试使用代码
从.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) {
}
});
我收到此错误
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。
答案 0 :(得分:1)
.getFile(file)
似乎是您的问题 - 什么是file
?这将zip下载到您的本地文件系统,它作为例外状态显示为“没有这样的文件或目录”。
尝试getBytes()
或getStream()
在内存中下载,或选择要写入的有效文件。
答案 1 :(得分:0)
您只需要提供两个参数,即要在其中提供该文件的第一个文件或第二个名称 喜欢:
storageRefrence.getFile(fileDirectory, fileName).addOnCompleteListener(new ...);