---
title: "FileUpload component | zenit Zig UI"
description: "File picking and a drop target. Browse, the drop zone, the file list and the app callback form one testable state."
url: https://ui.surf/zenit/components/upload
language: en
alternate_zh: https://ui.surf/zenit/zh/components/upload.md
alternate_es: https://ui.surf/zenit/es/components/upload.md
alternate_ja: https://ui.surf/zenit/ja/components/upload.md
alternate_ko: https://ui.surf/zenit/ko/components/upload.md
alternate_fr: https://ui.surf/zenit/fr/components/upload.md
alternate_de: https://ui.surf/zenit/de/components/upload.md
project: zenit v0.1.0-alpha (Zig 0.15.2, macOS)
source: https://github.com/version-next/zenit
---

# FileUpload

`ui.widgets.FileUpload`

File picking and a drop target.

[Video](https://ui.surf/zenit/media/stories/upload.mp4?v=30b9aa65f9)

**BEHAVIOR CONTRACT**

Browse, the drop zone, the file list and the app callback form one testable state.

**RECORDED INTERACTION**

The harness clicks Browse…; the story fills in a deterministic file path.

`examples/storybook/stories.zig:3069`

```zig
pub fn buildFileUpload(scope: *ui.Scope, cx: *ui.Cx) anyerror!*ui.Node {
    const a = cx.allocator;
    const c = try col(cx, 12);
    const story = try cx.bindState(FileUploadStory, .{ .state = undefined });
    const fu = try ui.widgets.FileUpload(.{
        .width = 380,
        .on_browse = cx.on(FileUploadStory, story, FileUploadStory.browse),
    }, scope, cx);
    story.state = fu.state;
    fu.wrapper.meta.ownership.meta.test_id = "story.upload.wrapper";
    // 拖放 drop zone：e2e 用 dragAt 往这块矩形里注入 entered/dropped
    fu.state.drop_zone.meta.ownership.meta.test_id = "story.upload.dropzone";
    try c.appendChild(a, fu.wrapper);
    return c;
}
```

[View source on GitHubexamples/storybook/stories.zig:3069](https://github.com/version-next/zenit/blob/HEAD/examples/storybook/stories.zig#L3069)

The story's verbatim source from the Storybook (zenit 4c50245 2026-10-01). `W` is `ui.widgets`; `col` / `row` / `label` are small Storybook layout helpers.

### FileUploadProps

`ui.widgets.FileUpload`

[src/ui/components/file\_upload/mod.zig:26](https://github.com/version-next/zenit/blob/HEAD/src/ui/components/file_upload/mod.zig#L26)

```zig
fn mountFileUpload(props: FileUploadProps, scope: *Scope, cx: *Cx) !FileUploadMount
```

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `width` | `f32` | `360` | — |
| `max_files` | `usize` | `8` | — |
| `hint` | `[]const u8` | `"Click Browse to add files"` | — |
| `on_browse` | `?core.HandlerRef` | `null` | Browse 按钮回调（宿主调起对话框后用 state.addFile 回填）。 null = 默认原生 NSOpenPanel（cx.openFilePanel）。 |
| `on_change` | `?core.HandlerRef` | `null` | 文件列表变化回调 |

### FileUploadMount

`ui.widgets.FileUpload`

[src/ui/components/file\_upload/mod.zig:199](https://github.com/version-next/zenit/blob/HEAD/src/ui/components/file_upload/mod.zig#L199)

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `wrapper` | `*Node` | — | — |
| `state` | `*FileUploadState` | — | — |
