从 readAsBinaryString 读取 AsDataURL?
我想将图像作为二进制文件保存到用户本地主机以供将来参考,然后在以后从这个二进制文件生成一个 dataurl,问题是,它不起作用。
var reader = new FileReader();
reader.onload = function(file){
this.file = file.target.result;
}.bind(this);
reader.readAsBinaryString(asset);
var reader = new FileReader();
reader.onload = function(image){
this.image = image.target.result;
}.bind(this);
reader.readAsDataURL(this.file);
这可能看起来有点反常,但是图像数据被放入本地存储中,然后在稍后的日期(也许一分钟,也许一周)我希望能够从中生成图像。
有什么想法吗?谢谢!
I want to save an image as binary to the users localhost for future reference, then at a later date, generate a dataurl from this binary, problem is, it's not working.
var reader = new FileReader();
reader.onload = function(file){
this.file = file.target.result;
}.bind(this);
reader.readAsBinaryString(asset);
var reader = new FileReader();
reader.onload = function(image){
this.image = image.target.result;
}.bind(this);
reader.readAsDataURL(this.file);
This might seem a little peverse, but the image data is being put in localstorage, then at a later date (maybe a minute, maybe a week) I want to be able to generate an image from it.
Any ideas? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法可能是将其作为数据 URL 读取,并将其保存到 localStorage 中。但是,如果您确实需要二进制数据,那么您可以单独保存它们。然后,当您需要生成图像时,只需执行以下操作:
It would probably be easiest to just read it as a data URL, and save that into localStorage. However, if you REALLY need the binary data, then you could just save them separately. Then, when you need to generate the image, just do something like: