Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @app.route('/api/v1.0/download/getfile')
- def stream_file():
- file_name = app.config['MY_DATA_ROOT'] + "/test.txt"
- def generate():
- f = open(file_name)
- while True:
- line = f.readline()
- if line.startswith("last line"):
- break
- else:
- yield line.encode('utf-8')
- return app.response_class(generate(), mimetype='application/octet-stream')
- getFile() {
- let options = new RequestOptions({responseType: ResponseContentType.Blob});
- return this.http.get(this.getFileURL, options)
- .map((response: Response) => {return <Blob>response.blob();});
- }
- onDownloadButtonClicked(): void {
- this.genService.getFile()
- .subscribe(fileData => {FileSaver.saveAs(fileData, "test.txt");});
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement