首页 文章

从React Native上传到Firebase存储

提问于
浏览
1

我'm seeing a lot of talk about uploading to Firebase storage from React Native, but all seem to be how to get around the fact that React Native doesn' t支持Blob或文件 . 但是Firebase有一个用于上传base64编码文件的 putString 方法 .

例如,为什么此代码在浏览器中工作,而在React Native中不起作用:

var base64String = "iVBORw0KGgoAAAA...";
firebase
  .storage()
  .ref()
  .child(`test/test.png`)
  .putString(base64String, 'base64')
  .then(function(snapshot) {
    console.log('Uploaded a base64 string!');
  })
  .catch(function(err) {
    console.log('Problems', err);
  });

React Native中没有给出错误,但没有文件到达Firebase . 是什么赋予了?

1 回答

  • 4

    Firebase存储JS dev在这里 .

    要清楚, at time of writing (Sept 2 2016) Firebase Storage uploads are not supported in React Native.

    要回答关于为什么上传在浏览器中工作而不是React Native的问题:我们的putString()方法不需要Blob支持,但是如果传入base64字符串,我们的库仍然必须能够以某种方式发送二进制数据 .

    在现代浏览器中,您可以将二进制数据存储在ArrayBuffer中,并将其作为XMLHttpRequest或Fetch请求的主体发送 - 在React Native中不是这样 .

    据我们所知,React Native核心库目前不提供一种发送内存二进制数据作为HTTP请求主体的好方法 .

相关问题