Reputation: 4343
I've implemented a button which should allow me to download a zip file from Firebase Storage.
This is my code
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();}
}
})
The problem is that it always fails and calls the FailureListener
how can this happen?
this is the stacktrace of the Exception:
error getting token java.util.concurrent.ExecutionException: com.google.firebase.FirebaseApiNotAvailableException: firebase-auth is not linked, please fall back to unauthenticated mode. 07-22 11:33:57.991 4272-4417/com.dancam.chords E/StorageException: StorageException has occurred. User does not have permission to access this object
This is my firebase storage rules
service firebase.storage {
match /b/chords-d1534.appspot.com/o {
match /{allPaths=**} {
allow read: if true; //if request.auth != null;
}
}
}
Upvotes: 1
Views: 1973
Reputation: 2419
You are downloading the file in a wrong way. Your reference to a file should be:
FirebaseStorage storage = FirebaseStorage.getInstance();
final StorageReference storageRef = storage.getReference();
final StorageReference imageRef = storageRef.child("path/to/file.zip");
And use it:
imageRef.getFile(imageFile).addOnSuccess...
com.google.firebase.FirebaseApiNotAvailableException: firebase-auth is not linked, please fall back to unauthenticated mode. 07-22 11:33:57.991 4272-4417/com.dancam.chords
Try linking the firebase-auth
library (add this into your app-level build.gradle
):
compile 'com.google.firebase:firebase-auth:11.0.2'
Upvotes: 2