简体   繁体   English

从React Native上传到Firebase存储

[英]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.

相关问题 在 React Native 中将数据从数组上传到 Firebase 存储和 Firebase 数据库 - Upload data to firebase storage and Firebase database from array in react native 在 React Native 中使用 Promise.all() 从 Firebase 存储中获取多个图像上传的下载 URL - Getting Download URLs from Firebase Storage on Multiple Image Upload Using Promise.all() in React Native 反应本机从 firebase STORAGE 检索 json - React native retrieve json from firebase STORAGE 将相机拍摄的图像上传到React Native上的Firebase存储 - Upload image taken with camera to firebase storage on React Native 尝试将 blob 上传到 Firebase 存储时出错(React Native) - Error when trying to upload blob to Firebase Storage (React Native) Firebase 存储 - 使用 React Native 上传图像,加载预览时出错 - Firebase Storage - Upload Image with React Native, Error loading Preview 使用 react native expo 将文件上传到 firebase 存储 - Upload files to firebase storage using react native expo Expo Camera Photo Upload To Firebase Storage 未定义 - React Native - Expo Camera Photo Upload To Firebase Storage is undefined - React Native React Native Image Upload的Firebase存储权限未知错误 - Firebase Storage Permission unknown error with React Native Image Upload 上传图片到 Firebase 9 用 React 存储? - Upload image to Firebase 9 storage with React?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM