android - 将文件从 Firebase 下载到 Android
问题描述
我已将一些 doc 文件存储在 Firebase 存储中的文件夹“Colleges_names”中。我想在我的安卓应用程序中下载它们。当我单击所需的按钮下载文件时,没有任何反应。
public void onClick(View view) {
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl("gs://du-admissions-app.appspot.com");
StorageReference islandRef = storageRef.child("COLLEGES-NAMES").child("CLG_BA(ENGLISH).docx");
File rootPath = new File(Environment.getExternalStorageDirectory(), "file_name");
if(!rootPath.exists()) {
rootPath.mkdirs();
}
final File localFile = new File(rootPath,"CLG_BA(ENGLISH).docx");
islandRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Log.e("firebase ",";local tem file created created " +localFile.toString());
// updateDb(timestamp,localFile.toString(),position);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e("firebase ",";local tem file not created created " +exception.toString());
}
});
解决方案
您无法使用扩展名检索这些文件,您应该首先以编程方式上传文件,获取downloadUrl()
上传的文件,然后检索该文件并downloadUrl()
下载文件。
我建议您阅读此内容。
推荐阅读
- angular - 两种方式的数据绑定在 Angular 9+ 中无法与 ng-select 一起使用
- java - 如何在考试选项中显示大小图像在android中保持纵横比
- javascript - 如何使用 JavaScript 获得多个模型图像弹出窗口。我正在使用 W3School 模型图像
- vala - Vala 如何使用多线程处理引用计数?
- arrays - 我的任务是将我的字符串转换为多维数组中的大写
- windows - 如何安装polymer3?
- python - 为什么按钮不会在 Tkinter 中显示
- c++ - 如何重载具有可变数量参数的函数
- python - 使用 Pycharm Python 进行网页抓取
- android - RecyclerView 水平网格间距 ItemDecorator 未按预期工作