From a9abd933b5e9a7c7ac140b81fa3b22866de107ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Thu, 24 Sep 2020 13:09:53 +0200 Subject: [PATCH] Use multipart for snapshot uploads (#2076) * Use multipart for snapshot uploads * Wrap I/O and run in executor * revert 7f26b43 * remove cleanup --- supervisor/api/snapshots.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/supervisor/api/snapshots.py b/supervisor/api/snapshots.py index 6e73b946a..3b018c7d5 100644 --- a/supervisor/api/snapshots.py +++ b/supervisor/api/snapshots.py @@ -182,11 +182,15 @@ class APISnapshots(CoreSysAttributes): """Upload a snapshot file.""" with TemporaryDirectory(dir=str(self.sys_config.path_tmp)) as temp_dir: tar_file = Path(temp_dir, "snapshot.tar") - + reader = await request.multipart() + contents = await reader.next() try: with tar_file.open("wb") as snapshot: - async for data in request.content.iter_any(): - snapshot.write(data) + while True: + chunk = await contents.read_chunk() + if not chunk: + break + snapshot.write(chunk) except OSError as err: _LOGGER.error("Can't write new snapshot file: %s", err) @@ -199,6 +203,6 @@ class APISnapshots(CoreSysAttributes): self.sys_snapshots.import_snapshot(tar_file) ) - if snapshot: - return {ATTR_SLUG: snapshot.slug} - return False + if snapshot: + return {ATTR_SLUG: snapshot.slug} + return False