Javascript Can';找不到变量atob React Native+;火基误差
我有一个post屏幕,在那里我可以从相机卷中选择一个图像并键入一个文本,我希望它保存在Javascript Can';找不到变量atob React Native+;火基误差,javascript,node.js,reactjs,firebase,react-native,Javascript,Node.js,Reactjs,Firebase,React Native,我有一个post屏幕,在那里我可以从相机卷中选择一个图像并键入一个文本,我希望它保存在Firebase中。 这是我在fire.js中的代码 addPost = async({text,localUri}) => { const remoteUri = await this.uploadPhotoAsync(localUri) return new Promise((res,rej) => { this.firestore.collection("p
Firebase
中。
这是我在fire.js中的代码
addPost = async({text,localUri}) => {
const remoteUri = await this.uploadPhotoAsync(localUri)
return new Promise((res,rej) => {
this.firestore.collection("posts").add({
text,
uid: this.uid,
timestamp:this.timestamp,
image: remoteUri
})
.then(ref => {
res(ref)
})
.catch(error => {
rej(error)
})
})
}
uploadPhotoAsync = async uri => {
const path = `photos/${this.uid}/${Date.now()}.jpg`
return new Promise(async (res,rej) => {
const response = await fetch(uri)
const file = await response.blob()
let upload = firebase.storage().ref(path).put(file)
upload.on(firebase.storage.TaskEvent.STATE_CHANGED,snapshot => {},
err => {
rej(err)
},
async () => {
const url = await upload.snapshot.ref.getDownloadURL()
res(url)
}
)
})
}
这是我的postscreen.js
屏幕,在这里我得到了一个错误找不到变量atob
请给我一个解决方案
handlePost = () => {
Fire.shared.addPost({text:this.state.text.trim(),
localUri:this.state.image })
.then(ref => {
this.setState({text:"",image:undefined})
this.props.navigation.goBack()
}).catch(error => {
alert(error)
})
}
pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing:true,
aspect:[4,3]
})
if(!result.cancelled) {
this.setState({image: result.uri})
}
}
顺便说一句,我可以看到图像保存在Firestore
存储中,但我看不到Firestore
数据库中的文本和照片这是某些版本的firebase
中的一个错误
一种解决方法是在app.js
中导入base64,并在未定义的情况下对其进行定义
import {decode, encode} from 'base-64'
if (!global.btoa) { global.btoa = encode }
if (!global.atob) { global.atob = decode }
你在某处使用了这个atob
,但在使用之前没有定义它。我不知道,我甚至不知道atob实际上是什么,但错误不在你共享的代码片段中。