【问题标题】:firestore upload a file : Unsupported field value: a custom File objectfirestore上传文件:不支持的字段值:自定义文件对象
【发布时间】:2018-07-07 11:34:48
【问题描述】:

我正在尝试在 firestore 中上传文件,并且以下代码正在运行:

 export const ticketEdit = values => {
  return async (dispatch, getState, { getFirebase, getFirestore }) => {
    const firestore = getFirestore();

    // delete file
    const file = values.file && values.file;
    delete values.file;

    try {
      // uploadFile
      if (file) await dispatch(ticketUploadFile(file, ticketId));

      // notification
      toastr.success(i18n.t("Success", i18n.t("The ticket is updated")));

    } catch (e) {
      console.log(e);
    }
  };
};

但是,如果我将删除文件的行放在上面

// delete file
const file = values.file && values.file;
delete values.file; 

在这样的 try catch 语句中:

 export const ticketEdit = values => {
  return async (dispatch, getState, { getFirebase, getFirestore }) => {
    const firestore = getFirestore();
    try {
      // delete file
      const file = values.file && values.file;
      delete values.file;
      if (file) await dispatch(ticketUploadFile(file, ticketId));

      // notification
      toastr.success(i18n.t("Success", i18n.t("The ticket is updated")));

    } catch (e) {
      console.log(e);
    }
  };
};

我得到了错误

不支持的字段值:自定义文件对象。

我想知道为什么。谢谢!

【问题讨论】:

    标签: javascript reactjs firebase google-cloud-firestore


    【解决方案1】:

    问题不是 try catch 语句,而是我在删除文件之前尝试更新值。

    经验教训:在更新文档之前删除文件。

    【讨论】:

      猜你喜欢
      • 2021-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-10
      相关资源
      最近更新 更多