preview-by-url 现在返回原始文件流(与/{fileId}/preview一致),前端用iframe直接显示。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
925 B
925 B
管理端文件预览接口(更新)
日期: 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 类型
前端使用
// 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 编码。