React-dropzone: Base64 data string of file

Created on 7 Mar 2016  路  3Comments  路  Source: react-dropzone/react-dropzone

Hello and thank you for a great component!

Is there an easy way of converting the files passed to the onDrop event to base64?

Thank you

Most helpful comment

Maybe this example might help:

onDropHandler(files) {      
      var file = files[0]
      const reader = new FileReader();
      reader.onload = (event) => {
        console.log(event.target.result);
      };
      reader.readAsDataURL(file);
}

All 3 comments

Just convert to whatever you want in the onDrop callback. It gets the files object from the browser. See https://github.com/okonet/react-dropzone/blob/master/src/index.js#L98

Maybe this example might help:

onDropHandler(files) {      
      var file = files[0]
      const reader = new FileReader();
      reader.onload = (event) => {
        console.log(event.target.result);
      };
      reader.readAsDataURL(file);
}

Maybe this example might help:

onDropHandler(files) {      
      var file = files[0]
      const reader = new FileReader();
      reader.onload = (event) => {
        console.log(event.target.result);
      };
      reader.readAsDataURL(file);
}

You are simply awesome buddy!!!!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

steverecio picture steverecio  路  4Comments

xuefanzhang picture xuefanzhang  路  4Comments

christiantigre picture christiantigre  路  4Comments

0xdevalias picture 0xdevalias  路  4Comments

timothyallan picture timothyallan  路  4Comments