Angular6 如何在angular 6中将图像保存在本地存储器上
我是新来的。我想在本地存储器上存储图像数据Angular6 如何在angular 6中将图像保存在本地存储器上,angular6,Angular6,我是新来的。我想在本地存储器上存储图像数据 localStorage.setItem("imgData", JSON.stringify(this.files)); 这将保存数据,但没有值。 如何保存请帮助我有一些类似于您的问题,它可以帮助您 renderPNG(fileName: string) { let reader = new FileReader(); reader.addEventListener("load", () = > { this.f
localStorage.setItem("imgData", JSON.stringify(this.files));
这将保存数据,但没有值。
如何保存请帮助我有一些类似于您的问题,它可以帮助您
renderPNG(fileName: string) {
let reader = new FileReader();
reader.addEventListener("load", () = > {
this.files = reader.result;
localStorage.setItem('imgData', JSON.stringify(this.files));
}, false);
this.files = JSON.parse(localStorage.getItem('imgData'));
if (!this.files) {
this.downloadService.downloadFileSystem(fileName, 'png')
.subscribe(response = > {
if (response && response.body.size > 0) {
reader.readAsDataURL(response.body);
}
});
}
}
我有一些类似于你的问题,它可以帮助你
renderPNG(fileName: string) {
let reader = new FileReader();
reader.addEventListener("load", () = > {
this.files = reader.result;
localStorage.setItem('imgData', JSON.stringify(this.files));
}, false);
this.files = JSON.parse(localStorage.getItem('imgData'));
if (!this.files) {
this.downloadService.downloadFileSystem(fileName, 'png')
.subscribe(response = > {
if (response && response.body.size > 0) {
reader.readAsDataURL(response.body);
}
});
}
}
使用fetch
fetch('http://cors-anywhere.herokuapp.com/https://lorempixel.com/640/480/?60789', {
headers: {},
}).then((response) => {
return response.blob();
}).then((blob) => {
console.log(blob);
}).catch((e) => console.log(e));
并用
读取文件并获取url
await fs.readString(this.dirPath + '/' + fileName).then(async (blob: Blob) => {
if (!!blob) {
if (blob.type === 'text/html' || blob.type === 'application/octet-stream') {
await fs.removeFile(this.dirPath + '/' + fileName);
} else {
const url = window.URL.createObjectURL(blob);
}
}
}).catch((err) => {
throw (err);
});
IonicFramework库中使用的参考
fetch('http://cors-anywhere.herokuapp.com/https://lorempixel.com/640/480/?60789', {
headers: {},
}).then((response) => {
return response.blob();
}).then((blob) => {
console.log(blob);
}).catch((e) => console.log(e));
并用
读取文件并获取url
await fs.readString(this.dirPath + '/' + fileName).then(async (blob: Blob) => {
if (!!blob) {
if (blob.type === 'text/html' || blob.type === 'application/octet-stream') {
await fs.removeFile(this.dirPath + '/' + fileName);
} else {
const url = window.URL.createObjectURL(blob);
}
}
}).catch((err) => {
throw (err);
});
IonicFramework库中使用的参考您可以发布您拥有的解决方案。如果发现您遗漏了,那么您可以在收到澄清后对其进行编辑。您可以发布您的解决方案。如果发现您遗漏了,那么您可以在收到澄清后对其进行编辑