fix: image preview in artifacts panel

This commit is contained in:
hjlarry 2026-02-05 15:28:04 +08:00
parent d690b97568
commit 71f15741b0
2 changed files with 33 additions and 1 deletions

View File

@ -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.

View File

@ -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",
)