Firebase 文本文件下载错误
Posted
技术标签:
【中文标题】Firebase 文本文件下载错误【英文标题】:Firebase Text File download error 【发布时间】:2017-01-24 02:59:56 【问题描述】:我是 android 和 Firebase 的新手。基本上,我正在尝试从 Firebase 下载文件并将其存储在 Android 存储中,但我收到了一个奇怪的错误 "ENOENT: No such file or directory error"
。我也有写存储权限。
代码:
public class MainActivity extends AppCompatActivity
private StorageReference mStorageRef;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mStorageRef = FirebaseStorage.getInstance().getReference().child("20JAN2017.txt");
System.out.println("......"+mStorageRef);
Uri url;
mStorageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>()
@Override
public void onSuccess(Uri uri)
FileDownloadTask file = mStorageRef.getFile(uri);
file.addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>()
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot)
System.out.println("task snapshot..."+taskSnapshot.getStorage());
);
file.addOnFailureListener(new OnFailureListener()
@Override
public void onFailure(@NonNull Exception e)
System.out.println("Error:"+e);
);
file.addOnCompleteListener(new OnCompleteListener<FileDownloadTask.TaskSnapshot>()
@Override
public void onComplete(@NonNull Task<FileDownloadTask.TaskSnapshot> task)
System.out.println("task completed");
);
);
错误:
01-23 21:53:19.502 10974-11033/indian.stock.screener E/FileDownloadTask: Exception occurred during file download
java.io.IOException: open failed: ENOENT (No such file or directory)
at java.io.File.createNewFile(File.java:946)
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:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
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:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
01-23 21:53:19.712 10974-11033/indian.stock.screener E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 200
任何帮助将不胜感激。
【问题讨论】:
您想将该文件保存在哪里?输入显示保存文件的绝对路径的代码。 【参考方案1】:mStorageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>()
@Override
public void onSuccess(Uri uri)
FileDownloadTask file = mStorageRef.getFile(uri);
...
);
是你的问题。 getDownloadUrl()
返回类似:https://firebasestorage.googleapis.com/...
而 getFile()
的参数期望本地文件系统可以解析 file:///tmp/...
。
contentResolver 无法解析 HTTPS URL,因为它无法写入 URL(它不是文件系统可以访问的文件)。
真的,你只想使用reference.getFile(/* appropriate local file */)
,而不是获取下载URL,或者通过getBytes()
或getStream()
在内存中下载;
【讨论】:
以上是关于Firebase 文本文件下载错误的主要内容,如果未能解决你的问题,请参考以下文章
将图像上传到 Firebase 存储并同时将文本输入到 Firestore 时出错
从 Firebase 数据库中检索用户数据并显示在用户配置文件文本字段中
Android:从运行时生成的文本字段中将数据保存到Firebase
Firebase会恢复单个文本数据并将其设置为textview