[英]Missing image uploaded on firebase storage (Using cloud function to update firestore DB)
I currently building a web application (build with react, nodejs & firebase) where I have a form where users can upload an image and fill in other information.我目前正在构建一个 web 应用程序(使用 react、nodejs 和 firebase 构建),我有一个表单,用户可以在其中上传图像并填写其他信息。
When the user submits the form:当用户提交表单时:
Below is roughly the code.下面是大致的代码。 No issue with this.这没有问题。
exports.onFileUploaded = functions.storage.object().onFinalize(async obj => {
// embed new file url
return firestore
.collection("user")
.doc(docId)
.update({
image: fileURL
})
.catch(e => console.error(e))
})
The problem is, for some occasions, I found out the document on storage is updated with the image URL, but the object is not found on the storage.问题是,在某些情况下,我发现存储上的文档更新为图像 URL,但在存储上找不到 object。 Technically it won't be possible because the only way a document got an image URL is after the cloud function listens to an event that a file is uploaded to storage.从技术上讲,这是不可能的,因为文档获取图像 URL 的唯一方法是在云 function 侦听文件上传到存储的事件之后。
Do you guys have any clue what should I do to fix this?你们有什么线索我该怎么做才能解决这个问题吗? Or do you guys have any idea how should I handle this better?或者你们知道我应该如何更好地处理这个问题吗?
Any idea would be greatly appreciated.任何想法将不胜感激。
Following this video that suits your example, I can see that instead of doing it all at once, it is advisable to do it step by step confirming the success of each step with a onSuccess() which will prevent concurrency that might lead to what you're experiencing.按照这个适合您的示例的视频,我可以看到,与其一次性完成所有操作,不如使用 onSuccess() 逐步确认每个步骤的成功,这将防止可能导致您发生的并发'正在经历。
You can see example of their videos that will include the aforementioned resource here .您可以在此处查看包含上述资源的视频示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.