上传图片停止工作后的Firebase反应本机

时间:2019-10-23 15:23:05

标签: react-native firebase-storage react-native-firebase

我正在使用Firebase存储,但是上传图像后Firebase停止工作。该应用程序继续运行,但Firebase没有响应。 而且我不知道如何解决这个问题。

const uploadImage = async (user, uri, imageName, mime = "image/jpg") => {
const Blob = RNFetchBlob.polyfill.Blob
  const fs = RNFetchBlob.fs
  window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
  window.Blob = Blob

  return new Promise((resolve, reject) => {
      const uploadUri = Platform.OS === "ios" ? uri.replace("file://", "") : uri
      let uploadBlob = null
      const imageRef = firebase.storage().ref(`Chats/${user}`).child(imageName)
      fs.readFile(uploadUri, "base64")
      .then((data) => {
        return Blob.build(data, {type: `${mime};BASE64`})
      })
      .then((blob) => {
        uploadBlob = blob
        return imageRef.put(blob, {contentType: mime})
      })
      .then(() => {
        uploadBlob.close()
        return imageRef.getDownloadURL()
      })
      .then((url) => {
        alert(url)
        resolve(url)
        console.log(url)
      })
      .catch((error) => {
        console.log(error)
        alert(error)
        reject(error) 
      })
    })
}

0 个答案:

没有答案