5

In the HTML5, it introduced the FileReader API. I can't really understand the difference between readAsBinaryString() and readAsDataURL(). I read docs from several places, but still can't fully understand. Can someone give some code examples to help me understand the differences?

1 Answer 1

14

If you use readAsDataURL(), you get the data back in a data URI format. So something like the src attribute here:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot">

If you use readAsBinaryString(), the result will be the raw bits. You can then use one of the low level binary APIs to manipulate the data or post it to the server.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.