SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. downloadfile(filePath: string){
  2.         return this.http
  3.             .get( URL_API_REST + 'downloadMaj?filePath='+ filePath)
  4.             .map(res => new Blob([res], {type: 'application/zip'}))
  5.     }
  6.      
  7. downloadfileComponent(filePath: string){
  8.         this.appService.downloadfile(filePath)
  9.             .subscribe(data => this.getZipFile(data)),
  10.                 error => console.log("Error downloading the file."),
  11.                 () => console.log('Completed file download.');
  12.     }
  13.  
  14.  
  15. getZipFile(data: any){
  16.         var a: any = document.createElement("a");
  17.         document.body.appendChild(a);
  18.  
  19.         a.style = "display: none";
  20.         var blob = new Blob([data], { type: 'application/zip' });
  21.  
  22.         var url= window.URL.createObjectURL(blob);
  23.  
  24.         a.href = url;
  25.         a.download = "test.zip";
  26.         a.click();
  27.         window.URL.revokeObjectURL(url);
  28.  
  29.     }
  30.      
  31. public void downloadMaj(@RequestParam(value = "filePath") String filePath, HttpServletResponse response) {
  32.  
  33.         System.out.println("downloadMaj");
  34.         File fichierZip = new File(filePath);
  35.  
  36.         try {
  37.             System.out.println("nom du fichier:" + fichierZip.getName());
  38.             InputStream inputStream = new FileInputStream(fichierZip);
  39.  
  40.             response.addHeader("Content-Disposition", "attachment; filename="+fichierZip.getName());
  41.             response.setHeader("Content-Type", "application/octet-stream");
  42.  
  43.             org.apache.commons.io.IOUtils.copy(inputStream, response.getOutputStream());
  44.             response.getOutputStream().flush();
  45.         } catch (FileNotFoundException e) {
  46.             e.printStackTrace();
  47.         } catch (IOException e) {
  48.             e.printStackTrace();
  49.         }
  50.     }
  51.      
  52. const options:any = {
  53.     headers: new HttpHeaders({'Content-Type': 'file type of an particular document'}),
  54.     withCredentials: true,
  55.     responseType:'arraybuffer'
  56.   };      
  57.  
  58.     return this.http.get<Content>(url,options);
  59.  
  60.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top