Skip to content

Commit 3b5757f

Browse files
committed
first download then copy @pcrespov
1 parent 4a2d251 commit 3b5757f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

clients/python/src/osparc/_api_files_api.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
)
2828
from urllib.parse import urljoin
2929
import aiofiles
30+
from tempfile import NamedTemporaryFile
31+
import shutil
3032
from ._utils import (
3133
DEFAULT_TIMEOUT_SECONDS,
3234
PaginationGenerator,
@@ -94,9 +96,6 @@ async def download_file_async(
9496
)
9597
async with aiofiles.tempfile.NamedTemporaryFile(
9698
mode="wb",
97-
dir=f"{destination_folder.resolve()}"
98-
if destination_folder is not None
99-
else None,
10099
delete=False,
101100
) as downloaded_file:
102101
async with AsyncHttpClient(
@@ -111,7 +110,13 @@ async def download_file_async(
111110
response.raise_for_status()
112111
async for chunk in response.aiter_bytes():
113112
await downloaded_file.write(chunk)
114-
return f"{downloaded_file.name}"
113+
dest_file = f"{downloaded_file.name}"
114+
if destination_folder is not None:
115+
dest_file = NamedTemporaryFile(dir=destination_folder, delete=False).name
116+
shutil.move(
117+
f"{downloaded_file.name}", dest_file
118+
) # aiofiles doesnt seem to have an async variant of this
119+
return dest_file
115120

116121
def upload_file(
117122
self,

0 commit comments

Comments
 (0)