Angular 8: Read from local storage, modify and save back to same file

旧巷老猫 提交于 2020-01-16 12:00:48

问题


I'm using the following code to read data from local storage on the client side:

fileChange(event) 
{
    let file = event.target.files[0];
    var reader = new FileReader();
    reader.readAsText (file);
    reader.onload = () => {
      console.log (reader.result);
    }
    
    let fileSaverService = new FileSaverService; 
    var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
    fileSaverService.save (file, "hello.txt");

The contents in 'file' is saved to "hello.txt" This is not what I need. I want to modify the contents of the selected file (event.target.files[0]).

Thank you in advance, Zvika

来源:https://stackoverflow.com/questions/59162408/angular-8-read-from-local-storage-modify-and-save-back-to-same-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!