0

How can I download w local folder containing HTML files using Angular?

I tried this:

   readFile(file: File) {
    var reader = new FileReader();
    reader.onload = () => {
        console.log(reader.result);
    };
    reader.readAsText(file);
}

 download(){
  this.file= "../monFichier/file.html"
  this.zip.file("file.yaml", this.readFile(this.file));

  this.fileUrl = this.zip.generateAsync({type:"blob"}).then(function (blob) { // 1) generate the zip file
    FileSaver.saveAs(blob, "downloadables.zip");                          // 2) trigger the download
    }, function (err) {
        console.log('err: '+ err);
    });
}

the code this.readFile(file) brings an error because the property file is not of type File.How can i read the content of this file so that it can be added to the zip file?

3
  • you send a fileUrl .. what you expect ?? If you set a folder, iterate through all files from it. Commented Jun 20, 2020 at 8:47
  • I know sir thank you for your answer ,the problem is that i don't know how to do that. should i do like this:( const data = '../monFichier.zip';) and then how can i call the files into that folder? Commented Jun 20, 2020 at 9:04
  • medium.com/@tarekabdelkhalek/… Commented Jun 20, 2020 at 9:25

2 Answers 2

0

there are a lot o resources ! just search :

AngularJS Upload and Post Multiple Files

Upload multiple files in angular

Upload multiple File Using angularjs with custom data for each one?

https://stackoverflow.com/a/44385918

Sign up to request clarification or add additional context in comments.

1 Comment

I am not trying to upload files infact i want to generate a file from the HTML of a component.
0

Best solution as per new chrome specification https://developers.google.com/web/updates/2018/02/chrome-65-deprecations

async downloadBrochure(url: string) {
    try {
      const res = await this.httpClient.get(url, { responseType: 'blob' }).toPromise();
      this.downloadFile(res);
    } catch (e) {
      console.log(e.body.message);
    }
  }

  downloadFile(data) {
    const url = window.URL.createObjectURL(data);
    const e = document.createElement('a');
    e.href = url;
    e.download = url.substr(url.lastIndexOf('/') + 1);
    document.body.appendChild(e);
    e.click();
    document.body.removeChild(e);
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.