问题
I did the base64 utf-8 encoding of the email. Because it is a database key. However, the following problems arise. I need help.
setValue at /user/aW1hZ2VfNTk1NkBuYXZlci5jb20= failed: DatabaseError: Invalid token in path
databaseReference.child("user").child(util.getBase64encode(email)).setValue(userModel)
help me...
回答1:
In my case, the encoded string was having a new line at the end. Using Base64.NO_WRAP as mentioned by @Arvin in this answer worked as a solution. My encoding function now looks like:
public static String encodeToBase64(String strToEncode) {
byte[] data = null;
try {
data = strToEncode.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return Base64.encodeToString(data, Base64.NO_WRAP);
}
If you're aiming to be safe like what @BobSnyder mentioned in the comments above, you could still use URL_SAFE and just trim the String just to make sure.
来源:https://stackoverflow.com/questions/44160089/android-firebase-database-invalid-token-in-path