反应本机+;Firebase存储:base64和blob不工作

反应本机+;Firebase存储:base64和blob不工作,firebase,react-native,firebase-storage,Firebase,React Native,Firebase Storage,我试图使用将我的图像文件编码为base64或blob,但两者都不起作用。我还使用这个:管理图像选择器 尝试1:使用图像选择器的.data方法,该方法应返回base64字符串 const blah = uuid.v4(); firebase .storage() .ref('images') .child(`${blah}.jpg`) .putString(file.data, 'base64', { contentType: 'image/jpeg' }) 但这会引发:Fire

我试图使用将我的图像文件编码为base64或blob,但两者都不起作用。我还使用这个:管理图像选择器

尝试1:使用图像选择器的
.data
方法,该方法应返回base64字符串

const blah = uuid.v4();
firebase
  .storage()
  .ref('images')
  .child(`${blah}.jpg`)
  .putString(file.data, 'base64', { contentType: 'image/jpeg' })
但这会引发:
Firebase存储:字符串与格式“base64”不匹配:找到无效字符

尝试2:使用

但是,它正在返回:
Firebase存储:索引0处的
put
中的参数无效:应为Blob或文件。

尝试使用3:base64

但这再次抛出:
Firebase存储:字符串与格式“base64”不匹配:找到无效字符

有人知道我做错了什么吗?

关于(尝试1)您必须使用“数据url”:

.putString(file.data, 'data_url', { contentType: 'image/jpeg' })

回到我使用5.5.6版的那一天,最近我更新到了6.2.0版,并遇到了相同的问题

const uri = Platform.OS === 'ios' ? response.uri.replace('file://', '') : response.uri
const imageRef = storage().ref('images/').child("blah")
await imageRef.put(uri)
const imageUrl = await imageRef.getDownloadURL()

我刚把
.put
改成
.putFile
,一切又恢复了正常

我遇到了完全相同的问题。真正奇怪的是,当react本机调试器打开时,.data会工作。这里有一个输入错误,类型是“data\u URL”,顺便说一句,正确的值是BASE64…是的,对不起,这是一个输入错误。当我写下答案时,“base64”不起作用
.putString(file.data, 'data_url', { contentType: 'image/jpeg' })
const uri = Platform.OS === 'ios' ? response.uri.replace('file://', '') : response.uri
const imageRef = storage().ref('images/').child("blah")
await imageRef.put(uri)
const imageUrl = await imageRef.getDownloadURL()