React-dropzone: Base64

Created on 29 Jun 2017  路  5Comments  路  Source: react-dropzone/react-dropzone

is there a way to directly retrieve the file encoded with base64? or convert it on the fly?

Most helpful comment

@chenfengyanyu

onDropGeneral = (currentGeneralPhoto) => {
      const reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = (event) => {
        this.setState({
          generalPhotos: this.state.generalPhotos.concat([{ base64: event.target.result }])
        });
      };
    }
  }

All 5 comments

I have the same promble. @CarlosUvaSilva do you save it ?

@chenfengyanyu

onDropGeneral = (currentGeneralPhoto) => {
      const reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = (event) => {
        this.setState({
          generalPhotos: this.state.generalPhotos.concat([{ base64: event.target.result }])
        });
      };
    }
  }

@CarlosUvaSilva Thank you very much, i got it!

hey how can i use base 64 in my code for integration that function

@ndiyansah I've posted my solution on top. That last part saves the base64 in an array because I had more than one dropzones. If you only have one you can remove the concat and it will save it has a simple string

Was this page helpful?
0 / 5 - 0 ratings