【发布时间】:2020-06-16 14:29:39
【问题描述】:
我有这个帖子屏幕,我可以在其中从相机胶卷中选择一张图片并输入文字,我希望它保存在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 屏幕,我收到错误can't find variable 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数据库中的文字和照片
【问题讨论】:
-
你在某个地方使用了这个
atob,而你在使用前没有定义它。 -
我不是我什至不知道 atob 到底是什么
-
但错误不在您共享的 sn-ps 中。
标签: javascript node.js reactjs firebase react-native