Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. @app.route('/api/v1.0/download/getfile')
  2. def stream_file():
  3. file_name = app.config['MY_DATA_ROOT'] + "/test.txt"
  4. def generate():
  5. f = open(file_name)
  6. while True:
  7. line = f.readline()
  8. if line.startswith("last line"):
  9. break
  10. else:
  11. yield line.encode('utf-8')
  12.  
  13.  
  14. return app.response_class(generate(), mimetype='application/octet-stream')
  15.  
  16. getFile() {
  17. let options = new RequestOptions({responseType: ResponseContentType.Blob});
  18. return this.http.get(this.getFileURL, options)
  19. .map((response: Response) => {return <Blob>response.blob();});
  20. }
  21.  
  22. onDownloadButtonClicked(): void {
  23. this.genService.getFile()
  24. .subscribe(fileData => {FileSaver.saveAs(fileData, "test.txt");});
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement