从Firebase存储下载映像

从Firebase存储下载映像

本文介绍了React-Native:从Firebase存储下载映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

预先信息:

我仍然打开了Firebase项目,但我仍然成功使用了Firebase数据库(所以 firebase.initializeApp(config) 工作)。
我在Firebase Storage的 / Images / 文件夹中上传了几张图片,并将其命名为 image1.jpg image2.jpg ,..

I still have a Firebase project opened and I am successfully still using the Firebase Database (So the firebase.initializeApp(config) works).I uploaded several Images at my Firebase Storage in the folder "/Images/" and named them image1.jpg, image2.jpg,..

React-Native:0.31.0,
Firebase:3.3.0

React-Native: 0.31.0,Firebase: 3.3.0

我想要的是什么:

我想从Firebase存储中获取图像并将它们放入<图片>

I want to get the Image from the Firebase Storage and put them into an <Image>

我实际做了什么:

var storageRef = firebase.storage().ref('Images/image1.jpg');

//1. Try:
storageRef.getDownloadURL().then(function(url) {
  console.log(url);
)}

//2. Try:
var sampleImage = storageRef.getDownloadURL().then(function(url) {
  console.log(url);
)}

//3. Try:
var sampleImage = storageRef.getDownloadURL();

有关代码的信息:


  1. 代码未到达 console.log(url) point

2.1。试图在< Image> sampleImage 作为来源 c>对象:空图像

2.1. Tried to use the sampleImage as source in a <Image> object: empty Image

2.2。试图 log sampleImage undefined

2.2. Tried to log the sampleImage: undefined

2.3。试过 log url 没达到这一点

3.1。试图在< Image> sampleImage 作为来源 c>对象:空图像

3.1. Tried to use the sampleImage as source in a <Image> object: empty Image

3.2。试过 log sampleImage {F:0,ka:undefined, o:{F:0,...}}

3.2. Tried to log the sampleImage: { F: 0, ka: undefined, o: { F: 0, ... } }

所有尝试在2-3分钟后返回相同的错误代码。

All tries returned the same error code after 2-3 minutes.

非常感谢您提前帮助。

推荐答案

更新

我向Firebase支持部门报告此问题,我收到了以下回复:

I reported this issue to Firebase support and I got the following response:

研究

看来这是一个由react-native的XMLHttpRequest操作引起的实际错误。以同样的方式尝试getDownloadURL()时,你会发生相同的事情(即达到最大重试时间)。

It appears that this is an actual bug caused by react-native's XMLHttpRequest acting up. When trying the getDownloadURL() in the same way you describe the same thing happens (ie. Max Retry time reached).

但是当覆盖react-native的XMLHttpRequest的polyfill时在中描述getDownloadURL()将正常完成并返回有效的URL。

However when overriding react-native's polyfill of XMLHttpRequest as described in this stack overflow thread getDownloadURL() will finish normally and return a valid URL.

我们正在使用react-native v0.33.0,Firebase v3.4.1

We are using react-native v0.33.0, Firebase v3.4.1

解决方法

我们一直在使用这种解决方法;绕过Firebase API:

We have been using this workaround in the meantime; bypassing the Firebase API:

var bucket = firebase.storage().ref().bucket;
var firebaseUrl = "https://firebasestorage.googleapis.com/v0/b/" + bucket + "/o/";
var finalUrl = firebaseUrl + 'path%2Fto%2Fresource';
firebase.auth().currentUser.getToken()
.then((token) => {
  fetch(finalUrl, {headers: {'Authorization' : 'Firebase ' + token}})
  .then((response) => response.json())
  .then((responseJson) => {
    var downloadURL = finalUrl + "?alt=media&token=" + responseJson.downloadTokens})
  })
});

这个问题似乎影响了少量用户,因为我只看到了问题否则。然而,这似乎是一个真正的错误,当它发生时非常虚弱,所以任何更多的输入将非常感激。

This is an issue that seems to affect a small amount of users since I have only seen the problem raised otherwise here. However this appears to be an actual bug and it is very debilitating when it occurs, so any more input would be greatly appreciated.

这篇关于React-Native:从Firebase存储下载映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 12:45