mirror of
https://github.com/GNS3/gns3-server
synced 2025-02-03 11:51:31 +00:00
parent
60a145afbb
commit
b3d83b1b0b
@ -286,22 +286,26 @@ class ProjectHandler:
|
|||||||
controller = Controller.instance()
|
controller = Controller.instance()
|
||||||
project = yield from controller.get_loaded_project(request.match_info["project_id"])
|
project = yield from controller.get_loaded_project(request.match_info["project_id"])
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
try:
|
||||||
datas = yield from export_project(project, tmp_dir, include_images=bool(request.get("include_images", "0")))
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
# We need to do that now because export could failed and raise an HTTP error
|
datas = yield from export_project(project, tmp_dir, include_images=bool(request.get("include_images", "0")))
|
||||||
# that why response start need to be the later possible
|
# We need to do that now because export could failed and raise an HTTP error
|
||||||
response.content_type = 'application/gns3project'
|
# that why response start need to be the later possible
|
||||||
response.headers['CONTENT-DISPOSITION'] = 'attachment; filename="{}.gns3project"'.format(project.name)
|
response.content_type = 'application/gns3project'
|
||||||
response.enable_chunked_encoding()
|
response.headers['CONTENT-DISPOSITION'] = 'attachment; filename="{}.gns3project"'.format(project.name)
|
||||||
# Very important: do not send a content length otherwise QT closes the connection (curl can consume the feed)
|
response.enable_chunked_encoding()
|
||||||
response.content_length = None
|
# Very important: do not send a content length otherwise QT closes the connection (curl can consume the feed)
|
||||||
response.start(request)
|
response.content_length = None
|
||||||
|
response.start(request)
|
||||||
|
|
||||||
for data in datas:
|
for data in datas:
|
||||||
response.write(data)
|
response.write(data)
|
||||||
yield from response.drain()
|
yield from response.drain()
|
||||||
|
|
||||||
yield from response.write_eof()
|
yield from response.write_eof()
|
||||||
|
# Will be raise if you have no space left or permission issue on your temporary directory
|
||||||
|
except OSError as e:
|
||||||
|
raise aiohttp.web.HTTPNotFound(text="Can't export project: {}".format(str(e)))
|
||||||
|
|
||||||
@Route.post(
|
@Route.post(
|
||||||
r"/projects/{project_id}/import",
|
r"/projects/{project_id}/import",
|
||||||
|
Loading…
Reference in New Issue
Block a user