[英]Upload to Firebase Storage from React Native
I'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 support Blobs or Files. 我看到很多关于从React Native上传到Firebase存储的讨论,但似乎都是如何解决React Native不支持Blob或文件这一事实。 But Firebase has a
putString
method for uploading base64 encoded files. 但是Firebase具有用于上传base64编码文件的
putString
方法。
Why does this code, for example, work in a browser but not in React Native: 例如,为什么此代码在浏览器中有效,但在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);
});
No errors are given in React Native, but no file arrive in Firebase. React Native中没有错误,但Firebase中没有文件到达。 What gives?
是什么赋予了?
Firebase Storage JS dev here. Firebase Storage JS开发人员在此处。
To be clear, at time of writing (Sept 2 2016) Firebase Storage uploads are not supported in React Native. 需要明确的是, 在撰写本文时(2016年9月2日),React Native不支持Firebase Storage上传。
To answer your question about why uploads work in a browser but not React Native: our putString() method doesn't need Blob support, but if you pass in a base64 string our library still has to be able to send the binary data somehow. 为了回答有关为什么上传在浏览器中而不是React Native上起作用的问题:我们的putString()方法不需要Blob支持,但是如果您传递base64字符串,我们的库仍必须能够以某种方式发送二进制数据。
In a modern browser, you can store binary data in an ArrayBuffer and send it as the body of an XMLHttpRequest or Fetch request - not so in React Native. 在现代浏览器中,您可以将二进制数据存储在ArrayBuffer中,并将其作为XMLHttpRequest或Fetch请求的主体发送-在React Native中不是这样。
As far we can tell, the React Native core libraries don't currently provide a good way to send in-memory binary data as the body of an HTTP request. 据我们所知,React Native核心库当前不提供一种将内存中的二进制数据作为HTTP请求的主体发送的好方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.