问题
I'm trying to upload an image file and get the image download URL using this code
private void UploadImage() {
String storageFileName = System.currentTimeMillis() + ".jpg"; // Time is used to ensure unique file name
FireBase_File = FireBase_Storage.child(storageFileName);
FireBase_File.putFile(UriBitmap).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if(task.isSuccessful()) {
FireBase_File.getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if(task.isSuccessful()) {
FireBase_DownloadURL = task.getResult().toString();
} else { Log.e(Global.Log_Tag + "Manage_Restaurant/UploadImage", "Failed to get download url [Exception]" + task.getException()); }
}
});
} else { Log.e(Global.Log_Tag + "Manage_Restaurant/UploadImage", "Failed to upload image [Exception]" + task.getException()); }
Finish_End();
}
});
}
and it worked fine until yesterday when I started getting this error messages in the console
E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
now I'm aware that this question has been asked before here but I tried everything this threads suggested and it's not working. it's also worth noting that I'm not using the auth firebase system. I tried using the login anonymously suggestion and it gave me this error.
com.google.firebase.auth.FirebaseAuthException: This operation is restricted to administrators only.
all replies are appreciated!
回答1:
You have to enable anonymous auth for your Firebase project:
In the Firebase Console, Auth -> Sign-in Methods enable the Anonymous sign-in method.
来源:https://stackoverflow.com/questions/61111453/firebase-error-when-trying-to-get-a-file-download-url-from-firebase