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
4 changes: 4 additions & 0 deletions ayon_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
delete,
download_file_to_stream,
download_file,
download_project_file,
download_project_file_to_stream,
upload_file_from_stream,
upload_file,
upload_reviewable,
Expand Down Expand Up @@ -349,6 +351,8 @@
"delete",
"download_file_to_stream",
"download_file",
"download_project_file",
"download_project_file_to_stream",
"upload_file_from_stream",
"upload_file",
"upload_reviewable",
Expand Down
74 changes: 74 additions & 0 deletions ayon_api/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,80 @@ def download_file(
)


def download_project_file(
project_name: str,
file_id: str,
filepath: str,
*,
chunk_size: Optional[int] = None,
progress: Optional[TransferProgress] = None,
) -> TransferProgress:
"""Download project file to filepath.

Project files are usually binary files, such as images, videos,
or other media files that can be accessed via api endpoint
'{server url}/api/projects/{project_name}/files/{file_id}'.

Args:
project_name (str): Project name.
file_id (str): File id.
filepath (str): Path where file will be downloaded.
chunk_size (Optional[int]): Size of chunks that are received
in single loop.
progress (Optional[TransferProgress]): Object that gives ability
to track download progress.

Returns:
TransferProgress: Progress object.

"""
con = get_server_api_connection()
return con.download_project_file(
project_name=project_name,
file_id=file_id,
filepath=filepath,
chunk_size=chunk_size,
progress=progress,
)


def download_project_file_to_stream(
project_name: str,
file_id: str,
stream: StreamType,
*,
chunk_size: Optional[int] = None,
progress: Optional[TransferProgress] = None,
) -> TransferProgress:
"""Download project file to a stream.

Project files are usually binary files, such as images, videos,
or other media files that can be accessed via api endpoint
'{server url}/api/projects/{project_name}/files/{file_id}'.

Args:
project_name (str): Project name.
file_id (str): File id.
stream (StreamType): Stream where output will be stored.
chunk_size (Optional[int]): Size of chunks that are received
in single loop.
progress (Optional[TransferProgress]): Object that gives ability
to track download progress.

Returns:
TransferProgress: Progress object.

"""
con = get_server_api_connection()
return con.download_project_file_to_stream(
project_name=project_name,
file_id=file_id,
stream=stream,
chunk_size=chunk_size,
progress=progress,
)


def upload_file_from_stream(
endpoint: str,
stream: StreamType,
Expand Down
70 changes: 70 additions & 0 deletions ayon_api/server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,76 @@ def download_file(

return progress

def download_project_file(
self,
project_name: str,
file_id: str,
filepath: str,
*,
chunk_size: Optional[int] = None,
progress: Optional[TransferProgress] = None,
) -> TransferProgress:
"""Download project file to filepath.

Project files are usually binary files, such as images, videos,
or other media files that can be accessed via api endpoint
'{server url}/api/projects/{project_name}/files/{file_id}'.

Args:
project_name (str): Project name.
file_id (str): File id.
filepath (str): Path where file will be downloaded.
chunk_size (Optional[int]): Size of chunks that are received
in single loop.
progress (Optional[TransferProgress]): Object that gives ability
to track download progress.

Returns:
TransferProgress: Progress object.

"""
return self.download_file(
f"api/projects/{project_name}/files/{file_id}",
filepath,
chunk_size=chunk_size,
progress=progress,
)

def download_project_file_to_stream(
self,
project_name: str,
file_id: str,
stream: StreamType,
*,
chunk_size: Optional[int] = None,
progress: Optional[TransferProgress] = None,
) -> TransferProgress:
"""Download project file to a stream.

Project files are usually binary files, such as images, videos,
or other media files that can be accessed via api endpoint
'{server url}/api/projects/{project_name}/files/{file_id}'.

Args:
project_name (str): Project name.
file_id (str): File id.
stream (StreamType): Stream where output will be stored.
chunk_size (Optional[int]): Size of chunks that are received
in single loop.
progress (Optional[TransferProgress]): Object that gives ability
to track download progress.

Returns:
TransferProgress: Progress object.

"""
return self.download_file_to_stream(
f"api/projects/{project_name}/files/{file_id}",
stream,
chunk_size=chunk_size,
progress=progress,
)

@staticmethod
def _upload_chunks_iter(
file_stream: StreamType,
Expand Down