Skip to content

Instantly share code, notes, and snippets.

@meetzaveri
Created June 25, 2018 11:07
Show Gist options
  • Save meetzaveri/9ef2fc24d4991218e003a940d61f4bae to your computer and use it in GitHub Desktop.
Save meetzaveri/9ef2fc24d4991218e003a940d61f4bae to your computer and use it in GitHub Desktop.

On handling image and then converting into blob

onHandelUpdateProfileUserAvatar = event => {
    // const target = event.target; const value = event.target.value;
    event.preventDefault();
    // console.log("this.state.fileInput", this.state.fileInput,
    // this.state.fileInput.files[0]);
    var file = this.state.fileInput.files[0];
    var fileName = file.name;
    var reader = new FileReader();
    reader.onload = function (e) {
      const s = e.target.result;
      localStorage.setItem("src", s);
      localStorage.setItem("tempavatar", s);
    };
    // console.log("SRC", src);
    reader.readAsDataURL(file);
    this.setState({
      imageFileName: fileName,
      onImgLoading: true
    }, () => {
      setTimeout(() => {
        this.previewImage();
      }, 1000);
    });

  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment