Reactjs React Redux Firebase文件上载
我是新来的。我正在尝试将文件上载到Firebase,虽然进展顺利,但我似乎无法将图片url保存到pictureUrl状态。我正在从promise中提取url,它工作正常,但是如何将promise中的下载url获取到pictureUrl状态?有什么想法吗 数据提交Reactjs React Redux Firebase文件上载,reactjs,firebase,react-redux,google-cloud-functions,es6-promise,Reactjs,Firebase,React Redux,Google Cloud Functions,Es6 Promise,我是新来的。我正在尝试将文件上载到Firebase,虽然进展顺利,但我似乎无法将图片url保存到pictureUrl状态。我正在从promise中提取url,它工作正常,但是如何将promise中的下载url获取到pictureUrl状态?有什么想法吗 数据提交 handleSubmit(e){ e.preventDefault(); console.log(this.state.picture) this.props.u
handleSubmit(e){
e.preventDefault();
console.log(this.state.picture)
this.props.uploadImage(this.state.picture)
const article = {
header: this.state.header,
tagLine: this.state.tagLine,
articleType: this.state.articleType,
system: this.state.system,
body: this.state.body,
pictureUrl: ???????
}
this.props.saveArticle(article);
console.log('Data saved!')
// Resets the state back to nothing
this.setState({
header: '',
tagLine: '',
articleType: '',
system: '',
body: '',
pictureUrl: ''
})
}
Firebase调用以上载文件
export function saveArticle(article, file){
return dispatch => database.push(article);
}
export function uploadImage(picture){
return dispatch => storage.child('/images/' + picture.name).put(picture).then((snapshot) => {
snapshot.ref.getDownloadURL().then(function(downloadURL) {
console.log('File available at: ', downloadURL)
})
})
console.log(picture)
}
render{
return{
<PDF
file={this.state.pdfUrl}
/>
}
}
你必须先让它进入状态,然后你才能把状态打回去。我也是新手,以前也有类似的问题。也许你应该看看这个例子 你必须回拨变量 例如
export function saveArticle(article, file){
return dispatch => database.push(article);
}
export function uploadImage(picture){
return dispatch => storage.child('/images/' + picture.name).put(picture).then((snapshot) => {
snapshot.ref.getDownloadURL().then(function(downloadURL) {
console.log('File available at: ', downloadURL)
})
})
console.log(picture)
}
render{
return{
<PDF
file={this.state.pdfUrl}
/>
}
}
渲染{
返回{
}
}