Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ansys/rep/client/jms/api/project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,9 @@ def _download_file(
if getattr(file, "hash", None) is None:
log.warning(f"No hash found for file {file.name}.")

Path(target_path).mkdir(parents=True, exist_ok=True)
download_link = f"{project_api.fs_bucket_url}/{file.storage_id}"
download_path = os.path.join(target_path, file.evaluation_path)
Path(download_path).parent.mkdir(parents=True, exist_ok=True)

with project_api.client.session.get(download_link, stream=stream) as r, open(
download_path, "wb"
Expand Down
28 changes: 28 additions & 0 deletions tests/jms/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ def test_files(self):
# Delete project again
jms_api.delete_project(proj)

def test_download_file_in_subdir(self):

client = self.client
jms_api = JmsApi(client)
proj = jms_api.create_project(
Project(name=f"rep_test_download_file_in_subdir", active=False)
)
project_api = ProjectApi(client, proj.id)

files = [
File(
name="file",
evaluation_path="subdir/file.txt",
type="text/plain",
src=io.BytesIO(b"This is my file"),
)
]

file = project_api.create_files(files)[0]

with tempfile.TemporaryDirectory() as tpath:
fpath = project_api.download_file(file, tpath)
with open(fpath, "r") as sf:
self.assertEqual("This is my file", sf.read())

# Delete project again
jms_api.delete_project(proj)


if __name__ == "__main__":
unittest.main()