CopyPastor

Detecting plagiarism made easy.

Score: 1.7982276146115024; Reported for: String similarity, Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2020-04-21
by Kishan Patel

Original Post

Original - Posted on 2020-03-10
by Vincent-cm



            
Present in both answers; Present only in the new answer; Present only in the old answer;

I think this may help you
It is correct for the Content-Type in your Request header since you indeed post a formDataForExport via backend.
But the way to handle the response seems wrong. I propose a solution below may help:
Assuming if you are referencing this fileSaver:
https://github.com/Hipparch/file-saver-typescript/blob/master/file-saver.ts
```downloadTheExport() { this.downloadfile().subscribe((resp: any) => { const fileSaver: any = new FileSaver(); fileSaver.responseData = resp.body; fileSaver.strFileName = 'testdata.xls'; fileSaver.strMimeType = 'application/vnd.ms-excel;charset=utf-8'; fileSaver.initSaveFile(); }); }
downloadfile() { const formDataForExport: FormData = new FormData(); formDataForExport.append('export', 'ALL');
return this.http.post('http://localhost:8080/service/exportExcel.php', formDataForExport, { headers: { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' }, responseType: 'blob', observe: 'response' }); }```
It is correct for the `Content-Type` in your **Request header** since you indeed post a formDataForExport via php backend.
But the way to handle the response seems wrong. I propose a solution below may help:
Assuming if you are referencing this fileSaver:
> https://github.com/Hipparch/file-saver-typescript/blob/master/file-saver.ts
**Recommend to include above script and use it since to handle different browser behaviour in saving files it is in complexity and not good for re-implement them.**
``` downloadTheExport() { this.downloadfile().subscribe((resp: any) => { const fileSaver: any = new FileSaver(); fileSaver.responseData = resp.body; fileSaver.strFileName = 'testdata.xls'; fileSaver.strMimeType = 'application/vnd.ms-excel;charset=utf-8'; fileSaver.initSaveFile(); }); }
downloadfile() { const formDataForExport: FormData = new FormData(); formDataForExport.append('export', 'ALL');
return this.http.post('http://localhost:8080/service/exportExcel.php', formDataForExport, { headers: { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' }, responseType: 'blob', observe: 'response' }); } ```

        
Present in both answers; Present only in the new answer; Present only in the old answer;