Skip to content
Open
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,
upload_project_file,
upload_project_file_from_stream,
download_project_file,
download_project_file_to_stream,
upload_file_from_stream,
Expand Down Expand Up @@ -351,6 +353,8 @@
"delete",
"download_file_to_stream",
"download_file",
"upload_project_file",
"upload_project_file_from_stream",
"download_project_file",
"download_project_file_to_stream",
"upload_file_from_stream",
Expand Down
68 changes: 68 additions & 0 deletions ayon_api/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,74 @@ def download_file(
)


def upload_project_file(
project_name: str,
filepath: str,
*,
chunk_size: Optional[int] = None,
progress: Optional[TransferProgress] = None,
) -> requests.Response:
"""Upload project file from a 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.
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:
requests.Response: Requests response.

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


def upload_project_file_from_stream(
project_name: str,
stream: StreamType,
*,
chunk_size: Optional[int] = None,
progress: Optional[TransferProgress] = None,
) -> requests.Response:
"""Upload project file from a 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.
stream (StreamType): Stream used as source for upload.
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:
requests.Response: Requests response.

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


def download_project_file(
project_name: str,
file_id: str,
Expand Down
68 changes: 68 additions & 0 deletions ayon_api/server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,74 @@ def download_file(

return progress

def upload_project_file(
self,
project_name: str,
filepath: str,
*,
chunk_size: Optional[int] = None,
progress: Optional[TransferProgress] = None,
) -> requests.Response:
"""Upload project file from a 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.
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:
requests.Response: Requests response.
"""
return self.upload_file(
f"api/projects/{project_name}/files",
filepath,
chunk_size=chunk_size,
progress=progress,
request_type=RequestTypes.post,
)

def upload_project_file_from_stream(
self,
project_name: str,
stream: StreamType,
*,
chunk_size: Optional[int] = None,
progress: Optional[TransferProgress] = None,
) -> requests.Response:
"""Upload project file from a 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.
stream (StreamType): Stream used as source for upload.
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:
requests.Response: Requests response.
"""
return self.upload_file_from_stream(
f"api/projects/{project_name}/files",
stream,
chunk_size=chunk_size,
progress=progress,
request_type=RequestTypes.post,
)

def download_project_file(
self,
project_name: str,
Expand Down