我已经修复了firebase实时数据库的读取和正确规则,但我仍然无法读取和写入它。
{
"rules": {
".read": "true",
".write": "true"
}
}
字符串
我也试过这个:
{
"rules": {
".read": true,
".write": true
}
}
型
Firebase存储规则:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if true;
}
}
}
型
Firebase存储规则工作正常,因为图像已上载,并已调用。
下面是我用来在数据库上设置值的代码,我已经定义了引用:
storageReference = FirebaseStorage.getInstance().getReference("Events_Details");
databaseReference = FirebaseDatabase.getInstance().getReference("Events_Details");
private void uploadUserInformationToDatabase() {
progressDialog.show();
if (image_uri != null) {
//this will create a big_number.jpg and when we call .child this means we are
//going to add something inside Events_Images Directory
StorageReference fileReference = storageReference.child(System.currentTimeMillis() + "." + getFileExtension(image_uri));
uploadTask = fileReference.putFile(image_uri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
//Now we need to get the url of the image that you have uploaded.
Task<Uri> uri = taskSnapshot.getStorage().getDownloadUrl();
while (!uri.isComplete());
String url = uri.getResult().toString();
createUserEvent.setImageUrl(url);
//now we will save this object in our database
String uploadId = databaseReference.push().getKey();
databaseReference.child(uploadId)
.setValue(createUserEvent);
progressDialog.dismiss();
Toast.makeText(context, "Event Created Successfully", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
}
});
} else {
progressDialog.dismiss();
Toast.makeText(context, "No File Selected", Toast.LENGTH_SHORT).show();
}
}
型
事件创建成功的吐司每次都显示,图像也上传到存储,但对象不保存在实时数据库中。而事件创建用户事件只是一个类,我想保存到实时数据库的对象沿着我将上传到存储的图像。图像总是在Firebase存储上传成功,并在它之后onSuccess函数被调用,并在onSuccess函数中我已经写了代码为对象保存实时数据库,但这不工作。请帮助我解决它,我已经浪费了2天我的,但不能解决这个问题。
2条答案
按热度按时间yacmzcpb1#
好的......我已经试过你的代码了。下面是修改后的函数:
第一个月
字符串
我正在成功上传到数据库。请检查您的数据库现在。
4zcjmb1e2#
Copyright © 2018 - 2019 www.hjk.com All Rights Reserved版权所有
字符串