umbraco-file-upload-preview by umbraco/umbraco-cms-backoffice-skills
npx skills add https://github.com/umbraco/umbraco-cms-backoffice-skills --skill umbraco-file-upload-preview文件上传预览是自定义的 Web 组件,用于在 Umbraco 中上传特定文件类型时渲染预览。它们允许您根据文件的 MIME 类型创建视觉表示,例如为图像显示缩略图、为音频显示波形图,或为特定文件格式显示自定义图标。
在实施前请务必获取最新文档:
umbraco-umbraco-element广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
export const manifests: Array<UmbExtensionManifest> = [
{
type: 'fileUploadPreview',
alias: 'My.FileUploadPreview.Custom',
name: 'Custom File Upload Preview',
weight: 100,
element: () => import('./my-file-preview.element.js'),
forMimeTypes: ['application/pdf', 'application/x-pdf'],
},
];
import { html, customElement, property, state } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import type { UmbFileUploadPreviewElement } from '@umbraco-cms/backoffice/media';
@customElement('my-file-preview')
export class MyFilePreviewElement extends UmbLitElement implements UmbFileUploadPreviewElement {
@property({ type: Object })
file?: File;
@state()
private _previewUrl?: string;
override updated(changedProperties: Map<string, unknown>) {
if (changedProperties.has('file') && this.file) {
this._previewUrl = URL.createObjectURL(this.file);
}
}
override disconnectedCallback() {
super.disconnectedCallback();
if (this._previewUrl) {
URL.revokeObjectURL(this._previewUrl);
}
}
override render() {
if (!this.file) return html``;
return html`
<div class="preview-container">
<uui-icon name="icon-document"></uui-icon>
<span>${this.file.name}</span>
</div>
`;
}
}
export default MyFilePreviewElement;
interface ManifestFileUploadPreview extends ManifestElement<UmbFileUploadPreviewElement> {
type: 'fileUploadPreview';
forMimeTypes: string | Array<string>; // 例如:'image/*', ['image/png', 'image/jpeg']
}
interface UmbFileUploadPreviewElement {
file?: File;
}
image/* - 所有图像类型video/* - 所有视频类型audio/* - 所有音频类型application/pdf - PDF 文件*/* - 所有类型的后备选项(配合较低的权重使用)就是这样!请务必获取最新的文档,保持示例最小化,并生成完整可用的代码。
每周安装数
73
代码仓库
GitHub 星标数
17
首次出现
2026年2月4日
安全审计
安装于
github-copilot53
cursor23
opencode21
codex21
gemini-cli19
amp19
File Upload Previews are custom web components that render previews for specific file types during upload in Umbraco. They allow you to create visual representations for files based on their MIME types, such as displaying thumbnails for images, waveforms for audio, or custom icons for specific file formats.
Always fetch the latest docs before implementing:
umbraco-umbraco-elementexport const manifests: Array<UmbExtensionManifest> = [
{
type: 'fileUploadPreview',
alias: 'My.FileUploadPreview.Custom',
name: 'Custom File Upload Preview',
weight: 100,
element: () => import('./my-file-preview.element.js'),
forMimeTypes: ['application/pdf', 'application/x-pdf'],
},
];
import { html, customElement, property, state } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import type { UmbFileUploadPreviewElement } from '@umbraco-cms/backoffice/media';
@customElement('my-file-preview')
export class MyFilePreviewElement extends UmbLitElement implements UmbFileUploadPreviewElement {
@property({ type: Object })
file?: File;
@state()
private _previewUrl?: string;
override updated(changedProperties: Map<string, unknown>) {
if (changedProperties.has('file') && this.file) {
this._previewUrl = URL.createObjectURL(this.file);
}
}
override disconnectedCallback() {
super.disconnectedCallback();
if (this._previewUrl) {
URL.revokeObjectURL(this._previewUrl);
}
}
override render() {
if (!this.file) return html``;
return html`
<div class="preview-container">
<uui-icon name="icon-document"></uui-icon>
<span>${this.file.name}</span>
</div>
`;
}
}
export default MyFilePreviewElement;
interface ManifestFileUploadPreview extends ManifestElement<UmbFileUploadPreviewElement> {
type: 'fileUploadPreview';
forMimeTypes: string | Array<string>; // e.g., 'image/*', ['image/png', 'image/jpeg']
}
interface UmbFileUploadPreviewElement {
file?: File;
}
image/* - All image typesvideo/* - All video typesaudio/* - All audio typesapplication/pdf - PDF files*/* - Fallback for all types (use with lower weight)That's it! Always fetch fresh docs, keep examples minimal, generate complete working code.
Weekly Installs
73
Repository
GitHub Stars
17
First Seen
Feb 4, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykPass
Installed on
github-copilot53
cursor23
opencode21
codex21
gemini-cli19
amp19
Angular开发者指南:从项目创建到组件与信号式状态管理的最佳实践
598 周安装