Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React Redux Firebase文件上载_Reactjs_Firebase_React Redux_Google Cloud Functions_Es6 Promise - Fatal编程技术网

Reactjs React Redux Firebase文件上载

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

我是新来的。我正在尝试将文件上载到Firebase,虽然进展顺利,但我似乎无法将图片url保存到pictureUrl状态。我正在从promise中提取url,它工作正常,但是如何将promise中的下载url获取到pictureUrl状态?有什么想法吗

数据提交

      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}
  />
 }
}
渲染{
返回{
}
}