首页 > 解决方案 > 为什么 Firestore 给我一个“不支持的字段值:自定义文件对象”,而我没有设置任何文件?

问题描述

我有一个图像文件数组,我循环并将每个元素(文件)转换为下载 url,它基本上是一个字符串。那么,当我尝试将此数组推送到 Firestore 时,
为什么会出现错误。Unsupported field value: a custom File object

注意:不是每次我使用set它都会给我一个错误。有时它会起作用,这也令人困惑。

images.forEach((file, index) => {
  const storageRef = firebase.storage().ref(`products/${uuid}.${fileExtenstion}`);
  const task = storageRef.put(file);
  task.on('state_changed', 
    function progress() {},
    function error() {},
    function complete() {
      storageRef.getDownloadURL().then(url => {
        imageFiles[index] = url;
      })
    }
  )
})

firestore.collection('products').doc().set({
  images: images
});

标签: javascriptfirebasegoogle-cloud-firestore

解决方案


推荐阅读