代码示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>显示图片</title>
</head>
<body>
<div>
<h1>图片展示</h1>
<img id="medicalImage" src="" alt="图片">
</div>
<script>
const instanceId = "id"; // 替换为实际的instanceId
// 构建完整的图片URL
const imageUrl = `http://localhost:8000/${instanceId}/images`;
// 使用fetch从后端获取图片并展示
fetch(imageUrl)
.then(response => response.blob())
.then(blob => {
const objectURL = URL.createObjectURL(blob);
document.getElementById('medicalImage').src = objectURL;
});
</script>
</body>
</html>
页面效果: