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
6 changes: 6 additions & 0 deletions ayon_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@
delete,
download_file_to_stream,
download_file,
upload_project_file,
upload_project_file_from_stream,
download_project_file,
download_project_file_to_stream,
delete_project_file,
upload_file_from_stream,
upload_file,
upload_reviewable,
Expand Down Expand Up @@ -351,8 +354,11 @@
"delete",
"download_file_to_stream",
"download_file",
"upload_project_file",
"upload_project_file_from_stream",
"download_project_file",
"download_project_file_to_stream",
"delete_project_file",
"upload_file_from_stream",
"upload_file",
"upload_reviewable",
Expand Down
120 changes: 120 additions & 0 deletions ayon_api/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,99 @@ def download_file(
)


def upload_project_file(
project_name: str,
filepath: str,
*,
content_type: Optional[str] = None,
filename: Optional[str] = None,
file_id: Optional[str] = None,
activity_id: Optional[str] = None,
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.
content_type (Optional[str]): MIME type of file.
filename (Optional[str]): Server filename, filename from filepath
is used if not passed.
file_id (Optional[str]): File id.
activity_id (Optional[str]): To which activity is file related.
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,
content_type=content_type,
filename=filename,
file_id=file_id,
activity_id=activity_id,
chunk_size=chunk_size,
progress=progress,
)


def upload_project_file_from_stream(
project_name: str,
stream: StreamType,
filename: str,
*,
content_type: Optional[str] = None,
file_id: Optional[str] = None,
activity_id: Optional[str] = None,
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.
filename (str): Name of file on server.
content_type (Optional[str]): MIME type of file.
file_id (Optional[str]): File id.
activity_id (Optional[str]): To which activity is file related.
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,
filename=filename,
content_type=content_type,
file_id=file_id,
activity_id=activity_id,
chunk_size=chunk_size,
progress=progress,
)


def download_project_file(
project_name: str,
file_id: str,
Expand Down Expand Up @@ -1067,11 +1160,27 @@ def download_project_file_to_stream(
)


def delete_project_file(
project_name: str,
file_id: str,
) -> None:
"""Delete project file.
"""
con = get_server_api_connection()
return con.delete_project_file(
project_name=project_name,
file_id=file_id,
)


def upload_file_from_stream(
endpoint: str,
stream: StreamType,
progress: Optional[TransferProgress] = None,
request_type: Optional[RequestType] = None,
*,
content_type: Optional[str] = None,
filename: Optional[str] = None,
**kwargs,
) -> requests.Response:
"""Upload file to server from bytes.
Expand All @@ -1087,6 +1196,8 @@ def upload_file_from_stream(
to track upload progress.
request_type (Optional[RequestType]): Type of request that will
be used to upload file.
content_type (Optional[str]): MIME type of the file.
filename (Optional[str]): Filename of file on server.
**kwargs (Any): Additional arguments that will be passed
to request function.

Expand All @@ -1100,6 +1211,8 @@ def upload_file_from_stream(
stream=stream,
progress=progress,
request_type=request_type,
content_type=content_type,
filename=filename,
**kwargs,
)

Expand All @@ -1109,6 +1222,9 @@ def upload_file(
filepath: str,
progress: Optional[TransferProgress] = None,
request_type: Optional[RequestType] = None,
*,
content_type: Optional[str] = None,
filename: Optional[str] = None,
**kwargs,
) -> requests.Response:
"""Upload file to server.
Expand All @@ -1124,6 +1240,8 @@ def upload_file(
to track upload progress.
request_type (Optional[RequestType]): Type of request that will
be used to upload file.
content_type (Optional[str]): MIME type of the file.
filename (Optional[str]): Filename of file on server.
**kwargs (Any): Additional arguments that will be passed
to request function.

Expand All @@ -1137,6 +1255,8 @@ def upload_file(
filepath=filepath,
progress=progress,
request_type=request_type,
content_type=content_type,
filename=filename,
**kwargs,
)

Expand Down
Loading