Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- downloadfile(filePath: string){
- return this.http
- .get( URL_API_REST + 'downloadMaj?filePath='+ filePath)
- .map(res => new Blob([res], {type: 'application/zip'}))
- }
- downloadfileComponent(filePath: string){
- this.appService.downloadfile(filePath)
- .subscribe(data => this.getZipFile(data)),
- error => console.log("Error downloading the file."),
- () => console.log('Completed file download.');
- }
- getZipFile(data: any){
- var a: any = document.createElement("a");
- document.body.appendChild(a);
- a.style = "display: none";
- var blob = new Blob([data], { type: 'application/zip' });
- var url= window.URL.createObjectURL(blob);
- a.href = url;
- a.download = "test.zip";
- a.click();
- window.URL.revokeObjectURL(url);
- }
- public void downloadMaj(@RequestParam(value = "filePath") String filePath, HttpServletResponse response) {
- System.out.println("downloadMaj");
- File fichierZip = new File(filePath);
- try {
- System.out.println("nom du fichier:" + fichierZip.getName());
- InputStream inputStream = new FileInputStream(fichierZip);
- response.addHeader("Content-Disposition", "attachment; filename="+fichierZip.getName());
- response.setHeader("Content-Type", "application/octet-stream");
- org.apache.commons.io.IOUtils.copy(inputStream, response.getOutputStream());
- response.getOutputStream().flush();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- const options:any = {
- headers: new HttpHeaders({'Content-Type': 'file type of an particular document'}),
- withCredentials: true,
- responseType:'arraybuffer'
- };
- return this.http.get<Content>(url,options);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement