Command palette

@yasinsensoy/native

React Native · Components

FileUpload

File upload field: picks with the system picker (photo/video or file; no permission needed), validates by rules (type, size, count, duplicates), and uploads with progress when upload is given; failed uploads can be retried.

10 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Code

import { Form, FileField, SubmitButton } from "@yasinsensoy/native";

const [state, formAction] = useActionState(save, null);

<Form action={formAction} state={state}>
  <FileField label="Attachments" name="attachments" multiple maxSize="5 MB" maxFiles={6} tooltip="You can also paste a screenshot with Ctrl+V."
    edit />
  <SubmitButton>Submit</SubmitButton>
</Form>

// Server action
async function save(_: unknown, data: FormData) {
  const attachments = data.getAll("attachments"); // File (new) and string (existing / uploaded)
}

Events

  1. Events appear here when you interact with the preview.

Gallery: photos, full screen preview (←/→, swipe)

Images, Video · Up to 10 MB · Up to 8 files

Profile photo: a single image, Change button

PNG, JPEG, WEBP · Up to 2 MB

Edit form: files on the server and type icons

  • sozlesme-2026.pdf

    471 KB

  • budget.xlsx

    89.1 KB

  • presentation-october.pptx

    5.2 MB

  • kaynak-code.zip

    12 MB

Inline: in compact forms

PDF · Up to 5 MB

Import

import { FileUpload } from "@yasinsensoy/native";

FileUpload

component

File upload field: picks with the system picker (photo/video or file; no permission needed), validates by rules (type, size, count, duplicates), and uploads with progress when upload is given; failed uploads can be retried. Same names as FileUpload on web. The pickers come from the @yasinsensoy/native/file-system module.

FileUpload(props: FileUploadProps): ReactElement<unknown, string | JSXElementConstructor<any>>

Examples

<FileUpload
  label="Photos"
  layout="gallery"
  multiple
  accept="image/*"
  maxSize="10 MB"
  maxFiles={6}
  upload={(file, { signal, onProgress }) =>
    FileSystem.upload("https://api.site.com/upload", { files: [file.uri!], signal, onProgress })}
/>

File size: a number of bytes or text with a unit ("5 MB", "500KB", "1.5 GB"). Units are base 1024 (1 KB = 1024 bytes).

type FileSize = number | `${number}${"" | " "}${"B" | "KB" | "MB" | "GB"}`

Upload status (same as web).

type FileUploadStatus = "queued" | "uploading" | "done" | "error"

A file in the list.

NameTypeDescription
idstringStable id.
namestringFile name.
size?number | undefinedBytes.
type?string | undefinedMIME type.
uri?string | undefinedLocal address (file://, Android content://); absent for a server file.
url?string | undefinedPreview/download address (a file on the server).
status?FileUploadStatus | undefinedUpload status.
progress?number | undefinedUpload percentage (0–100).
error?string | undefinedError message when the upload failed.
value?unknownReturn value of upload (e.g. the file id on the server).
width?number | undefinedImage/video width (pixels).
height?number | undefinedImage/video height (pixels).
original?MediaFile | undefinedOriginal file of an edited image/video (with edit). Re-editing starts from here; uri is the edited version.
edits?MediaEdits | undefinedApplied edits (with edit).

Initial file: an id is generated if not given.

type FileUploadInit = Omit<FileUploadItem, "id"> & { /** Item id; generated if omitted. */ id?: string | undefined; }
NameTypeDescription
namestringFile name.
size?number | undefinedBytes.
type?string | undefinedMIME type.
uri?string | undefinedLocal address (file://, Android content://); absent for a server file.
url?string | undefinedPreview/download address (a file on the server).
status?FileUploadStatus | undefinedUpload status.
progress?number | undefinedUpload percentage (0–100).
error?string | undefinedError message when the upload failed.
value?unknownReturn value of upload (e.g. the file id on the server).
width?number | undefinedImage/video width (pixels).
height?number | undefinedImage/video height (pixels).
original?MediaFile | undefinedOriginal file of an edited image/video (with edit). Re-editing starts from here; uri is the edited version.
edits?MediaEdits | undefinedApplied edits (with edit).
id?string | undefinedItem id; generated if omitted.

Rejection reason (same as web).

type FileRejectionReason = "type" | "size" | "minSize" | "count" | "duplicate" | "custom"

FileRejection

interface

A rejected file.

NameTypeDescription
filePickedFileThe rejected file.
reasonFileRejectionReasonWhy it was rejected.
messagestringMessage to show.

Values passed to the upload function.

NameTypeDescription
signalAbortSignalCancelled when the file is removed or the component unmounts. Pass it to FileSystem.upload.
onProgress(progress: number | { fraction: number | null; }) => voidProgress: 0–100 or a FileSystem.upload onProgress result.

Where to pick from.

type FileUploadSource = "auto" | "media" | "document"

Props of FileUpload.

Extends: FieldProps

NameTypeDefaultDescription
layout?"list" | "gallery""list"list: rows; gallery: square thumbnails.
multiple?booleanfalseMultiple files.
accept?string | readonly string[]Accepted types: "image/*", ".pdf", ["image/png", "application/pdf"].
maxSize?FileSizeMaximum size (5_000_000 or "5 MB").
minSize?FileSizeMinimum size.
maxFiles?numberMaximum files (with multiple).
validate?(file: PickedFile) => string | null | undefined | falseExtra validation: return an error message, or nothing if valid.
value?readonly FileUploadInit[]Files (controlled).
defaultValue?readonly FileUploadInit[]Initial files (e.g. the ones on the server).
onValueChange?(items: FileUploadItem[]) => voidWhen the list changes.
onReject?(rejections: FileRejection[]) => voidFiles that break the rules (the message also shows below the field).
upload?(file: FileUploadItem, context: FileUploadContext) => Promise<unknown>Upload when picked. The returned value becomes the item's value; if it throws the item is marked as failed and can be retried.
uploadConcurrency?number3Maximum concurrent uploads.
source?FileUploadSource"auto"Picker: media the photo/video picker, document the file picker, auto media if accept is only images/videos, otherwise files.
edit?boolean | FileUploadEditOptionsEdit images and videos with MediaEditor (crop, rotate, filters, drawing, trimming video). true enables all tools; for details see FileUploadEditOptions. The size rule is applied after editing.
pick?(options: { multiple: boolean; accept: string[]; }) => Promise<PickedFile[]>Your own picker (e.g. a camera); when given source is ignored.
placeholder?ReactNodeButton text.
hint?ReactNodeHint below the button; generated from the size/count limits if omitted.
icon?IconProp"upload"Button icon.
onItemPress?(item: FileUploadItem) => voidWhen a file is tapped (for preview, e.g. FileSystem.open).
readOnly?booleanRead-only: no adding/removing.
style?StyleProp<ViewStyle>Style of the root view.