문제

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!

도움이 되었습니까?

해결책

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:

var img = document.createElement("img");
img.setAttribute("src", localStorage.imageDataURL);
document.body.appendChild(img);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top