Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @app.route('/', cors=cors_config, methods=['GET'])
- def index():
- request = app.current_request
- file_name = "orders.csv"
- file_path = '/tmp/{}_{}'.format("Life", file_name)
- with open(file_path, 'w') as csvFile:
- field_names = ["OrderID", "OrderedBy", "Agent"]
- writer = csv.DictWriter(csvFile, fieldnames=field_names)
- writer.writeheader()
- for item in range(10):
- writer.writerow(
- rowdict={
- "OrderID": str(1),
- "OrderedBy": "noob",
- "Agent": "pro"
- }
- )
- csvFile.close()
- with open(file_path, 'rb') as f:
- contents = f.read()
- f.close()
- file_size = os.path.getsize(file_path)
- headers = {'Content-Type': 'application/octet-stream',
- 'Content-Disposition': 'attachment; filename={}'.format(file_name),
- 'Content-Length': str(os.path.getsize(file_path))
- }
- return Response(body=contents, headers=headers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement