HTML5 FileReader API中的readAsBinaryString()和readAsDataURL()之间的区别 [英] Difference between readAsBinaryString() and readAsDataURL() in HTML5 FileReader API

查看:314
本文介绍了HTML5 FileReader API中的readAsBinaryString()和readAsDataURL()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML5中,它引入了FileReader API.我真的无法理解readAsBinaryString()和readAsDataURL()之间的区别.我从多个地方阅读过文档,但仍然无法完全理解.有人可以提供一些代码示例来帮助我理解这些差异吗?

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?

推荐答案

如果使用readAsDataURL(),则会以数据URI格式获取数据.因此,类似于src属性:

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">

如果使用readAsBinaryString(),结果将是原始位.然后,您可以使用低级二进制API之一来处理数据或将其发布到服务器.

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.

这篇关于HTML5 FileReader API中的readAsBinaryString()和readAsDataURL()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆