reactjs - react-image-uploader upload on submit button -


i found this awesome react package uploading multiple images.

the images uploaded server once selected filesystem via browse window. want start uploading them when press "submit" button. can see preview, not sent unless button pressed. reason because have other data want sent images.

i beginner react, can please point me if there way achieve this? maybe extend * imagesuploader* class?

update: after looking @ package using (and reading bit of code), looks can't (easily) hook trigger uploading - is, not without forking project, adding own "pause" mechanism, , see if he'd accept pr.

he doesn't expose hooks manually start upload, callbacks onloadstart() , onloadend().

my initial thought somehow add generator function in onloadstart() pauses upload until call next() generator... but... not accomplished... sorry. i'll leave original answer in case needs info later.

add functions onchange event handler when user selects file gets triggered. add on change <input> element.

// example    class fileuploadcomponent extends react.component {    constructor() {      super()      this.state = {        file: ''      }      this.handlechange = this.handlechange.bind(this)      this.handlesubmit = this.handlesubmit.bind(this)    }    handlechange(e) {      this.setstate({file: e.target.files[0]})      // other "pre-submitted" logic here    }    handlesubmit(e) {      e.preventdefault()      const { file } = this.state      // file    }    render() {      return (        <div>          <input type='file' onchange={this.handlechange}/>          <button onclick={this.handlesubmit}></button>        </div>      )    }  }


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -