From b87b9cc35493920af6a4da4bfb53bb6cf7002df0 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:12:05 +0200 Subject: [PATCH] properly implement upload --- client/ayon_core/plugins/publish/integrate.py | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/client/ayon_core/plugins/publish/integrate.py b/client/ayon_core/plugins/publish/integrate.py index 3c29438f78..ababbd88fc 100644 --- a/client/ayon_core/plugins/publish/integrate.py +++ b/client/ayon_core/plugins/publish/integrate.py @@ -20,7 +20,7 @@ from ayon_api.operations import ( ) from ayon_api.utils import create_entity_id -from ayon_core.lib import source_hash +from ayon_core.lib import source_hash, get_media_mime_type from ayon_core.lib.file_transaction import ( FileTransaction, DuplicateDestinationError @@ -990,12 +990,10 @@ class IntegrateAsset(pyblish.api.InstancePlugin): } def _upload_reviewable(self, project_name, version_id, instance): - uploaded_labels = set() ayon_con = get_server_api_connection() base_headers = ayon_con.get_headers() - endpoint = ( - f"/api/projects/{project_name}/versions/{version_id}/reviewables" - ) + + uploaded_labels = set() for repre in instance.data["representations"]: repre_tags = repre.get("tags") or [] # Ignore representations that are not reviewable @@ -1014,13 +1012,25 @@ class IntegrateAsset(pyblish.api.InstancePlugin): repre_path = get_publish_repre_path( instance, repre, False ) - repre_ext = os.path.splitext(repre_path)[-1].lower() + if not repre_path or not os.path.exists(repre_path): + # TODO log skipper path + continue + content_type = get_media_mime_type(repre_path) + if not content_type: + self.log.warning("Could not determine Content-Type") + continue + + # Use output name as label if available label = repre.get("outputName") - if not label: - # TODO how to label the reviewable if there is no output name? - label = "Main" + query = "" + if label: + query = f"?label={label}" + endpoint = ( + f"/api/projects/{project_name}" + f"/versions/{version_id}/reviewables{query}" + ) # Make sure label is unique orig_label = label idx = 0 @@ -1033,13 +1043,15 @@ class IntegrateAsset(pyblish.api.InstancePlugin): # Upload the reviewable self.log.info(f"Uploading reviewable '{label}' ...") headers = copy.deepcopy(base_headers) + headers["Content-Type"] = content_type + headers["x-file-name"] = os.path.basename(repre_path) + self.log.info(f"Uploading reviewable {repre_path}") ayon_con.upload_file( - f"/api/projects/{project_name}/versions/{version_id}/reviewables", + endpoint, repre_path, headers=headers ) - def _validate_path_in_project_roots(self, anatomy, file_path): """Checks if 'file_path' starts with any of the roots.