【问题标题】:在应用关闭时反应本机 Firebase 存储上传中止
【发布时间】:2022-01-23 16:44:21
【问题描述】:

我有这个功能,可以将图像上传到 Firebase 存储。通常它可以工作,但是当用户在调用 ref.put(blob) 时关闭应用程序时,函数会中止并且图像不会上传。如果应用程序关闭,是否有某种方法可以在后台继续执行此功能?

export const uploadImage = (uri) => (
  new Promise((resolve, reject) => {

  const ref = storage
    .ref()
    .child(//path);

  fetch(uri)
    .then((response) => {
      return response.blob();
    })
    .then((blob) => {
      return ref.put(blob);
    })
    .then(() => {
      resolve();
    })
    .catch((err) => {
      reject(err);
    })
  })
);

【问题讨论】:

    标签: firebase react-native file-upload blob firebase-storage


    【解决方案1】:

    Firebase 中没有内置任何东西可以在后台继续上传。由于您使用react-native 标记,您可以考虑使用react-native-background-task 之类的东西在后台执行整个上传。

    【讨论】:

      猜你喜欢
      • 2023-01-21
      • 2020-02-22
      • 2021-10-21
      • 2019-08-29
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多