简体   繁体   English

firebase 存储上上传的缺少图像(使用云 function 更新 Firestore DB)

[英]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:当用户提交表单时:

  • other information will be stored directly in the firebase firestore.其他信息将直接存储在 firebase 火库中。
  • The image will be uploaded to firebase storage.图像将上传到 firebase 存储。 Only after that, my cloud function will listen to that event and update the collection accordingly with the image URL.只有在那之后,我的云 function 才会监听该事件并使用图像 URL 相应地更新集合。

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.

相关问题 使用Firebase Cloud功能检查存储中是否存在映像 - Check if image exists at storage with firebase cloud function 无法使用云删除 Firebase 存储映像 Function - Unable to delete Firebase Storage Image with Cloud Function 如何将映像从Expressjs更新到Google Cloud Storage / Firebase Storage - How update an image from Expressjs to Google Cloud Storage / Firebase Storage 使用 Firestore 云更新数据 function - Update data using firestore cloud function 如何使用 Cloud Function 从 Cloud Storage 获取 Firebase 的 object? - How to get object from Cloud Storage for Firebase using Cloud Function? 上传到Firebase存储时如何使用Cloud Functions for FIrebase获取mp3文件的持续时间 - How to get the duration of a mp3 file using Cloud Functions for FIrebase when uploaded to firebase storage 从可调用的 https 云 function 将图像上传到 Firebase 存储 - Upload an image into Firebase Storage from a callable https cloud function 通过云功能检索Firebase存储图像链接 - Retrieving a Firebase storage image link via Cloud Function 如何使用Cloud Functions for Firebase更新Firebase Cloud Firestore数据库中的值 - how to update a value in firebase cloud firestore database using Cloud Functions for Firebase 使用 Google Cloud Function 将数据从 firebase firestore 导出到 MeiliSearch - Exporting data from firebase firestore to MeiliSearch using Google Cloud Function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM