集合在Firebase控制台上具有默认权限。
我使用电子邮件和密码正确登录了用户。
user = await _auth.signInWithEmailAndPassword( email: "[email protected]", password: "password");
然后,在将图像成功上传到FireStorage之后,我也尝试运行事务以更新文档。
var fileName = _textController.text.toLowerCase();
StorageUploadTask putFile =
storage.ref().child("region/$fileName").putFile(_regionImage);
UploadTaskSnapshot uploadSnapshot = await putFile.future;
var regionData = new Map();
regionData["label"] = _textController.text;
var pictureData = new Map();
pictureData["url"] = uploadSnapshot.downloadUrl.toString();
pictureData["storage"] = "gs://app-db.appspot.com/region/$fileName";
regionData["picture"] = pictureData;
DocumentReference currentRegion =
Firestore.instance.collection("region").document(fileName);
Firestore.instance.runTransaction((transaction) async {
DocumentSnapshot freshSnap = await transaction.get(currentRegion);
print(freshSnap.exists);
//await transaction.set(freshSnap.reference, regionData);
await transaction.set(currentRegion, regionData);
print("instance created");
});
尝试运行事务时收到此错误。
如果我尝试设置为freshSnap.reference
或直接设置为,则相同currentRegion
。https://gist.github.com/matejthetree/f2a57c929d01919bd46da8ca6d5b6fb1
请注意,在第15行,交易开始时出现错误,但在我成功上载映像并将其下载到存储设备之前,FireStorage也没有收到身份验证令牌错误。
我应该如何在FireStore中进行文档创建
好像问题出在我创建地图的方式上。
Map<String, dynamic> regionData = new Map<String, dynamic>();
regionData["label"] = _textController.text;
Map<String, dynamic> pictureData = new Map<String, dynamic>();
pictureData["url"] = uploadSnapshot.downloadUrl.toString();
pictureData["storage"] = "gs://app-db.appspot.com/region/$fileName";
regionData["picture"] = pictureData;
DocumentReference currentRegion =
Firestore.instance.collection("region").document(fileName);
Firestore.instance.runTransaction((transaction) async {
await transaction.set(currentRegion, regionData);
print("instance created");
});
该代码现在有效
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句