hl-api-changelog/changelogs/2026-03/2026-03-23_admin_file_preview_v2.md
API Changelog Bot 70cf4ac59b changelog: 管理端文件预览接口更新(返回原始二进制流)
preview-by-url 现在返回原始文件流(与/{fileId}/preview一致),前端用iframe直接显示。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 20:45:32 +08:00

38 行
925 B
Markdown

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

# 管理端文件预览接口(更新)
**日期**: 2026-03-23
**类型**: 接口更新
---
## 接口
```
GET /admin/file/preview-by-url?url=编码后的完整OSS_URL
```
**无需登录,无需 token。**
## 返回内容
直接返回**原始文件二进制流**(与 `/{fileId}/preview` 一致):
- PDF → Content-Type: application/pdf
- 图片 → Content-Type: image/jpeg 等
- 其他 → 对应 MIME 类型
## 前端使用
```javascript
// iframe 嵌入推荐,PDF和图片都能直接显示
<iframe :src="`/api/admin/file/preview-by-url?url=${encodeURIComponent(ossUrl)}`"
width="100%" height="600px" />
// 或新窗口打开
window.open(`/api/admin/file/preview-by-url?url=${encodeURIComponent(ossUrl)}`)
// 或 img 标签(仅图片)
<img :src="`/api/admin/file/preview-by-url?url=${encodeURIComponent(ossUrl)}`" />
```
**注意**url 参数必须 `encodeURIComponent` 编码。