diff --git a/api/core/sandbox/inspector/base.py b/api/core/sandbox/inspector/base.py index 76f92a4f97..a5b783aff2 100644 --- a/api/core/sandbox/inspector/base.py +++ b/api/core/sandbox/inspector/base.py @@ -15,6 +15,26 @@ class SandboxFileSource(abc.ABC): self._app_id = app_id self._sandbox_id = sandbox_id + @staticmethod + def _guess_image_content_type(path: str) -> str | None: + image_mime_types = { + "jpg": "image/jpeg", + "jpeg": "image/jpeg", + "png": "image/png", + "gif": "image/gif", + "bmp": "image/bmp", + "tiff": "image/tiff", + "tif": "image/tiff", + "webp": "image/webp", + "svg": "image/svg+xml", + "ico": "image/vnd.microsoft.icon", + "heif": "image/heif", + "heic": "image/heic", + } + + extension = path.split(".")[-1] + return image_mime_types.get(extension) + @abc.abstractmethod def exists(self) -> bool: """Check if the sandbox source exists and is available. diff --git a/api/core/sandbox/inspector/runtime_source.py b/api/core/sandbox/inspector/runtime_source.py index 639b1d66d5..5300ca633a 100644 --- a/api/core/sandbox/inspector/runtime_source.py +++ b/api/core/sandbox/inspector/runtime_source.py @@ -161,9 +161,21 @@ print(json.dumps(entries)) logger.debug("Failed to cleanup temp archive %s: %s", archive_path, exc) else: try: + content_type = self._guess_image_content_type(path) + command = [ + "curl", + "-s", + "-f", + "-X", + "PUT", + ] + if content_type: + # to support image preview in artifacts panel, we need add content-type when upload to S3 + command.extend(["-H", f"Content-Type: {content_type}"]) + command.extend(["-T", path, upload_url]) execute( self._runtime, - ["curl", "-s", "-f", "-X", "PUT", "-T", path, upload_url], + command, timeout=self._UPLOAD_TIMEOUT_SECONDS, error_message="Failed to upload file from sandbox", )