
[英]How to download a file from Firebase Storage to the External_Storage of Android
[英]Android - Download a zip file from Firebase Storage
我实现了一个按钮,该按钮应该允许我从Firebase Storage下载zip文件。
这是我的代码
FirebaseStorage storage = FirebaseStorage.getInstance();
final StorageReference storageRef = storage.getReference();
.buttonCtaClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//download stuff
try {
File imageFile = File.createTempFile("Chords_Images", "zip");
storageRef.getFile(imageFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(SplashActivity.this, "file created", Toast.LENGTH_SHORT).show();
//TODO: download audio
startApp();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(SplashActivity.this, "An error accoured", Toast.LENGTH_SHORT).show();
}
});
} catch (IOException e) {e.printStackTrace();}
}
})
问题是它总是失败并调用FailureListener
怎么会发生?
这是异常的堆栈跟踪:
获取令牌java.util.concurrent.ExecutionException时出错:com.google.firebase.FirebaseApiNotAvailableException:firebase-auth未链接,请退回到未认证模式。 07-22 11:33:57.991 4272-4417 / com.dancam.chords E / StorageException:发生StorageException。 用户无权访问此对象
这是我的Firebase存储规则
service firebase.storage {
match /b/chords-d1534.appspot.com/o {
match /{allPaths=**} {
allow read: if true; //if request.auth != null;
}
}
}
您以错误的方式下载文件。 您对文件的引用应为:
FirebaseStorage storage = FirebaseStorage.getInstance();
final StorageReference storageRef = storage.getReference();
final StorageReference imageRef = storageRef.child("path/to/file.zip");
并使用它:
imageRef.getFile(imageFile).addOnSuccess...
com.google.firebase.FirebaseApiNotAvailableException: firebase-auth未链接 ,请退回到未经身份验证的模式。 07-22 11:33:57.991 4272-4417 / com.dancam.chords
尝试链接firebase-auth
库(将其添加到您的应用程序级别build.gradle
):
compile 'com.google.firebase:firebase-auth:11.0.2'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.