mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-04 22:41:12 +02:00
Upload images API
Conflicts: requirements.txt setup.py
This commit is contained in:
1 parent
61fb641215
commit
bb4ebbfe64
9 files changed
+121
-4
No files matched your search
@@ -444,3 +444,20 @@ class BaseManager:
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
@asyncio.coroutine
|
||||
def write_image(self, filename, stream):
|
||||
directory = self.get_images_directory()
|
||||
path = os.path.join(directory, os.path.basename(filename))
|
||||
log.info("Writting image file %s", path)
|
||||
try:
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
with open(path, 'wb+') as f:
|
||||
while True:
|
||||
packet = yield from stream.read(512)
|
||||
if not packet:
|
||||
break
|
||||
f.write(packet)
|
||||
os.chmod(path, stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPConflict(text="Could not write image: {} to {}".format(filename, e))
|
||||
Reference in new issue
Block a user