Skip to content

Inputs

FileUpload

Bit.BlazorUI

BitFileUpload is the transport half of working with files: it takes the files the user hands over and uploads them to a server endpoint over HTTP. Files arrive through the file dialog, a drag out of the OS, a clipboard paste, a whole folder or the camera on a phone, and go out automatically on selection or on demand, as a single request per file or in chunks. Every file reports its own progress and can be paused, resumed, canceled, retried and removed from the server again, and selections are validated on arrival against size, count, extension, MIME type, duplicate, image dimension and custom rules. The upload and remove requests are customizable down to a per-request async provider, which is what makes an expiring token or a presigned URL work over a long transfer, and the whole control is themable, templatable and announced to screen readers. For plain file selection without any uploading, reach for the BitFileInput component instead.

Usage

Every example is live. Open its code to see exactly what produced the component running underneath.

Basic

Out of the box the BitFileUpload offers three ways to hand a file over: click the browse button to open the file dialog, drag a file out of the OS and drop it anywhere on the component, or focus the component and paste a file from the clipboard. The selected file appears in the built-in file list with its name, its human-readable size and an upload button that starts sending it to the UploadUrl; while files hover over the component the browse button turns into a dashed drop indicator. During the upload the item shows a progress bar with pause and cancel buttons, and once it settles, a status message reports the outcome.

AllowDrop & AllowPaste

The two alternative selection routes can be switched off independently. AllowDrop controls dragging files out of the OS onto the component: turning it off keeps the drop from being handled and shows a "no drop" cursor, while still swallowing the event so the browser does not navigate away to the dropped file and lose the page state. AllowPaste controls pasting files from the clipboard; a paste is only delivered to the component while the focus is inside it, so the browse button has to be focused first. Both take effect immediately when toggled at runtime, as the checkboxes below demonstrate.



Description

Telling the user the rules before they run into them is the single biggest usability win an uploader can offer. Description renders a short hint under the browse button and - the part that is easy to forget - wires it to that button through aria-describedby, so a screen reader reads the constraints out together with the button instead of leaving them to be discovered by trial and error. Spell out the accepted types and the size ceiling there, matching whatever Accept, AllowedExtensions and MaxSize actually enforce. DescriptionTemplate takes over when the hint needs markup of its own, such as the icon below, and Classes.Description / Styles.Description restyle it.

PDF or DOCX, up to 5 MB.

Images only. Up to 2 MB.

Multiple

Multiple lets the file dialog hand over several files at once and lets a single drop or paste carry several files, each uploading independently with its own progress, pause, cancel and status. Without it the dialog is limited to one file and only the first file of a multi-file drop is taken.

AutoUpload

AutoUpload starts sending the files the moment they are selected, skipping the per-file upload button entirely - the pattern to reach for when selection itself expresses the intent to upload, like an avatar picker or an attachment area.

AutoReset

AutoReset clears the file list and the upload state just before the file dialog opens, so every browse starts from a clean slate - the list empties even if the dialog is then cancelled. Handy when a stale, already-uploaded selection lingering behind the dialog would be misleading.

Append

A new selection normally replaces whatever is in the list. Append keeps the existing files - along with their upload state - and adds the new selection to the end instead, letting the user build the batch up over several rounds of browsing, dropping or pasting.

AllowDuplicates

Building a batch up over several rounds of browsing makes it easy to pick the same file twice without noticing, and uploading it twice is rarely what anyone meant. Turning AllowDuplicates off rejects a newly selected file that matches one already in the list - by name, size and last modified time, which is as close to an identity as the browser exposes for a picked file - showing the DuplicateErrorMessage under it instead of sending it a second time. The rejection is not final: remove the file it duplicates and the copy becomes eligible again, since the rule is re-evaluated over the whole list on every change. Try selecting the same file twice below.

Size limits

MaxSize and MinSize bound the size of each file in bytes, while MaxTotalSize bounds what the whole list adds up to - the limit that actually matches a per-request or per-user storage quota, which a per-file ceiling alone cannot express. A file outside the allowed range is marked as not allowed right at selection time - with the MaxSizeErrorMessage, MinSizeErrorMessage or MaxTotalSizeErrorMessage shown under it - and it is never sent to the server; the file stays visible in the list so the user can see exactly what was rejected and why instead of it disappearing silently. Only the files that pass the other validations consume the total-size budget, and a file turned away by it becomes eligible again as soon as removals free up room.

Max 1 MB per file:



Min 1 KB per file:



Max 2 MB in total across the batch:



Custom error message:

Accept & AllowedExtensions

The two work at different moments and are both worth setting. Accept is passed straight to the accept attribute of the underlying input, which only hints the file dialog to pre-filter what it offers - it is a convenience, never a guarantee, since a drop, a paste or a "show all files" switch walks right past it. AllowedExtensions is the actual rule: it checks every file however it arrived and marks the mismatches as not allowed with the NotAllowedExtensionErrorMessage, so they stay visible in the list with their reason and are never sent.

Its entries are matched leniently - an extension may be written with or without its leading dot and in any casing - and an entry containing a slash is treated as a MIME type instead, with a trailing wildcard like image/* covering a whole group. When Accept is not set, the list also generates the accept attribute on its own, which is why setting AllowedExtensions alone is usually all you need; set Accept explicitly only when the dialog filter should differ from the rule.

Accept only (the dialog filters, but a dropped file of any type is still taken and uploaded):



AllowedExtensions (the rule, which also generates the accept attribute):



MIME types (every image plus PDFs):

MaxCount

MaxCount caps how many files the list can hold - 3 in this example. Files arriving beyond the cap stay visible but are marked as not allowed with the MaxCountErrorMessage and never uploaded, so the user sees exactly which files did not make it instead of them disappearing silently. Only files that pass the other validations consume a slot, so a file rejected for its size or type never pushes a good file over the cap, and a file already uploading or uploaded keeps the slot it holds rather than being taken back by a later selection. Combined with Append the cap applies to the whole accumulated list, not just a single selection - and since the cap is re-evaluated on every change, removing a file takes the next one waiting behind it back in.

FileValidator

When the built-in checks are not enough, FileValidator runs a custom function for each newly selected file after those checks pass. Returning an error message marks the file as not allowed and shows the message under it - the file is never uploaded; returning null accepts the file. Any rule expressible over the file's metadata works - this example rejects empty (zero-byte) files. A validator that throws only invalidates its own file, using the exception message as the error text, rather than aborting the whole selection.

Directory

Directory turns the picker into a folder picker: the dialog asks for a directory instead of a file and every file inside it - and inside its subfolders, at any depth - lands in the list as a separate upload with its own progress and status. It does the same for a drag and drop, walking a dropped folder into its contents rather than ignoring it, which the plain file input cannot do on its own. The browser warns the user before handing a whole folder over, and the usual validations still apply to every file that comes out of it, so pairing it with AllowedExtensions, MaxCount or MaxTotalSize is what keeps a stray folder from turning into a thousand uploads. Pair it with ConcurrentUploads to keep the transfers orderly.

Capture

On a phone or a tablet, Capture asks the browser to open the camera or the microphone directly instead of the file browser, which turns the uploader into a one-tap "take a photo and send it" control. "user" asks for the front (selfie) camera and "environment" for the rear one; which one is actually honored is up to the device, and a desktop browser ignores the attribute altogether and opens the usual file dialog. Combine it with Accept to say what kind of capture is wanted - an image, a video or an audio recording - and with AutoUpload so the shot goes out the moment it is taken.

Opens the rear camera on a mobile device.

Opens the front camera on a mobile device.

Preview

A file name is a poor way to tell one photo from another, so ShowPreview puts a thumbnail of every selected image at the head of its file item, letting the user confirm they picked the right picture before a single byte goes out. The thumbnail is produced entirely in the browser from an object URL, so nothing is uploaded to render it and non-image files simply keep the plain item. The URL is also handed back as soon as the file is removed or the component is reset, which is what keeps a long-lived page from holding every picture ever picked in memory. BitFileInfo.PreviewUrl exposes the same URL for a custom FileViewTemplate, and Classes.Preview / Styles.Preview restyle the built-in thumbnail.

The selected images are previewed right in the list.

Image dimensions

A size limit in bytes is a poor way to say "no tiny avatars" or "nothing bigger than 4K": what matters for an image is its pixels, and a heavily compressed photo can be small in bytes and enormous on screen. ReadImageDimensions decodes every selected image right in the browser and fills the Width and Height of its BitFileInfo before the validations run, so a FileValidator can turn an image away for its dimensions without a single byte leaving the machine - and the rejected file stays in the list with its reason, exactly like any other rejection.

Decoding is not free: a folder full of photos costs time and memory to walk through, which is why it is off by default and why the decoding runs a few images at a time rather than all at once. Non-image files, and images the browser cannot decode, simply keep both values null - a validator has to treat that as "unknown" rather than as a failure. The values are also there for a custom FileViewTemplate to render, as the second uploader below does.

Between 200x200 and 4000x4000 pixels:

Images between 200x200 and 4000x4000 pixels.


Showing the dimensions of each image:

Removable

ShowRemoveButton puts a remove button on each settled file item. A file whose bytes never reached the server is simply dropped from the view, while a file that has (partially or fully) uploaded is deleted from the server through a DELETE request to the RemoveUrl, carrying the file name as a query string and the file id in the BIT_FILE_ID header; a non-success response marks the file with the FailedRemoveMessage instead of pretending it is gone. RemoveButtonTitle localizes the button tooltip and its accessible label.

Events

Every stage of the process surfaces through a callback: OnChange fires whenever a file's status changes, OnInvalid right after it whenever a selection carries rejected files - handy for driving a summary or blocking a submit button - OnUploading right before a file's first request (the natural place to attach per-file HTTP headers like below), OnProgress on every progress tick, OnUploadComplete / OnUploadFailed when a file settles, OnRemoveComplete / OnRemoveFailed for removals, and OnAllUploadsComplete once the whole batch has reached a terminal state, which is what drives the message below. Try a file over 1 MB to see OnInvalid at work.


No File

Http requests

The upload and remove requests are fully customizable. Static UploadRequestHttpHeaders / RemoveRequestHttpHeaders and UploadRequestQueryStrings / RemoveRequestQueryStrings attach headers and query strings to the respective requests, and UploadRequestFormFields adds extra multipart fields next to the file content itself - the target folder, an album id, a caption - for the endpoints that read their metadata from the form rather than from the URL.



Each of the three has an async ...Provider counterpart, and the difference is not only that it is a function: a provider is invoked right before every single request - each file, and each chunk of a chunked file - while the static values are fixed once, when the files are selected. That is what makes a provider the right place for anything that expires: an access token that has to be fresh when the request actually goes out, or a presigned URL good for one upload only, which UploadUrlProvider mints for the endpoint itself. A value that never changes belongs in the static parameter instead, since a provider costs an await per request.


Requests so far: 0


The transport itself is configurable too: UploadRequestHttpMethod switches the verb ("POST" by default - a PUT is what presigned URL flows usually expect), UploadFormFieldName renames the form field carrying the file content ("file" by default), WithCredentials sends cookies and authorization headers along on cross-origin requests, and UploadTimeout fails a request - each file or chunk - that takes longer than the given time. On the other side, RemoveRequestHttpMethod does the same for the removal, whose "DELETE" some APIs would rather receive as a "POST".

Chunked

ChunkedUpload slices each file and sends it as a series of sequential requests instead of one monolithic one, which is what makes pausing, resuming and recovering large uploads practical: a paused or failed file resumes from the last successfully uploaded chunk rather than starting over, so a dropped connection costs one chunk instead of the whole transfer. ChunkSize pins the size of each slice in bytes, while AutoChunkSize adapts it to the observed connection speed on the fly, between 512 KB and 10 MB - large enough on a fast link to keep the request overhead negligible, small enough on a slow one to keep the progress moving and a retry cheap.

The server side reassembles the file, and every chunk request carries what it needs to do so reliably: the BIT_FILE_ID header correlating the chunks of one file, and the byte range of the chunk both as the standard Content-Range header (bytes from-to/total) and as the plain BIT_CHUNK_FROM, BIT_CHUNK_TO and BIT_FILE_SIZE headers for the handlers that would rather not parse it. Writing each chunk at its own offset rather than blindly appending is what makes the server correct in the face of a retried chunk. Note that CORS treats these as custom request headers, so a cross-origin endpoint has to allow them.



Adaptive chunk sizing:

Retry

Networks fail, so a professional uploader plans for it. AutoRetries retries a failed upload automatically - up to the given number of times per file, waiting AutoRetryDelay before each attempt - and in the chunked mode every retry resumes from the last successfully uploaded chunk instead of starting over. Pausing or canceling a file while a retry is still waiting out its delay wins over that retry, so the outcome the user asked for is the one that stands.

Not every failure deserves another attempt, so the budget is only spent where a second try could go differently: network errors, timeouts, 408, 429 and the 5xx server errors are retried, while the other 4xx - a 404 pointing nowhere, a 413 that is simply too large, a 401 - settle the file immediately rather than repeating an identical doomed request. ShouldAutoRetry replaces that rule with your own, receiving the file and the status code and returning whether to retry.

Once the automatic budget is exhausted the file settles as failed, and the item offers a retry button - distinct from the plain upload button of a never-started file, both in its icon and in its wording, so a second attempt never reads as a first one. Pressing it tries again with a fresh automatic budget, exactly like calling Upload with that file from code does. RetryIcon, RetryIconName and RetryButtonTitle restyle and localize it, falling back to their upload counterparts when unset.



A non-existing endpoint (404): the built-in rule does not retry it, so the file fails at once and offers the manual retry button.



The same endpoint with a ShouldAutoRetry that insists: watch it retry twice before settling.

ConcurrentUploads

By default every file of a batch is put on the wire at once, which is the fastest option on a healthy connection but not always the kindest one: browsers only keep a handful of connections open per host, and a server behind a rate limit or a slow disk would rather not meet fifty simultaneous uploads. ConcurrentUploads caps how many files may be in flight at the same time; the rest wait in a queue in selection order and each one starts the moment a slot frees up - whether the file holding it completed, failed, was canceled or was merely paused. Set it to 0 (the default) to keep starting everything at once.

The cap counts files, not requests: a chunked file holds its single slot for the whole run of its chunks rather than going back to the end of the queue between two of them. Note that the queue only governs the start of an upload, so a file started explicitly through Upload(file) waits its turn just like a file of a batch does.

A file waiting for its turn says so rather than looking exactly like one nobody asked to upload: its item shows the QueuedUploadMessage - "Waiting to upload" by default, and the place to translate it - drops the start button, since starting something already on its way would do nothing, and keeps a cancel button so it can be called off before its turn ever comes. BitFileInfo.IsQueued exposes the same state to a custom FileViewTemplate.

Two files at a time:



One file at a time (a strictly sequential queue), with a translated waiting message:

Overall progress

Besides the per-file progress, the component aggregates the batch as a whole: TotalSize and TotalUploadedSize expose the combined byte counts of the files that are actually being uploaded - rejected and removed files do not count - and OverallUploadProgress turns them into a single percentage, weighting every file by its size. Rendering it is a matter of re-reading those properties whenever OnProgress or OnChange fires, which is exactly what drives the BitProgress below. Select several files and upload them all to see the combined bar move.


0 %

Speed & time remaining

A percentage answers "how far along is this"; what a user waiting on a large upload actually wants to know is "how much longer". Every running file measures the speed of the request currently in flight and exposes it on its BitFileInfo: UploadSpeed in bytes per second and RemainingTime as a TimeSpan derived from it and the bytes still to send. Both are null while a file is not on the wire - before it starts, once it settles, and for the first fraction of a second of a request, where a reading taken over almost no time would say nothing but a huge number.

They are updated on every progress tick, so rendering them is a matter of re-reading them from OnProgress, as the summary below does. In the chunked mode the speed is measured over the chunk in flight, which is what makes it follow a connection that speeds up or slows down mid-file instead of averaging the whole transfer into a number that stops reacting.

The batch has the same two numbers of its own: TotalUploadSpeed adds up the speed of every file currently on the wire - what the connection as a whole is carrying, which is the honest figure when several files are uploading at once - and OverallRemainingTime divides the bytes still to go by it. Both are null while nothing is uploading, which is the difference between "not moving" and "moving at zero".



Batch: idle (-)

FileSizeFormatter

Each file item shows its uploaded and total size through a built-in humanizer that speaks English and counts in binary units. FileSizeFormatter takes that decision over: it receives a size in bytes and returns whatever text should appear, which is where a localized unit name, a different rounding, or the decimal base some platforms prefer belongs. The example below drops down to raw byte counts with thousands separators.

HideFileView

HideFileView takes the built-in file list away without taking the files with it: they are still selected, still validated, still uploaded and still reported through Files and the callbacks - they are simply not drawn. That is what you want when the surrounding page already shows the attachments in its own layout, when the uploader has to collapse into a single button, or when the list belongs somewhere else on the screen entirely. The example below renders its own summary from the OnChange callback while the component itself shows nothing but the browse button. Reach for FileViewTemplate instead when the list should stay where it is and only look different.


No file selected yet.

Templates

The default UI can be swapped out entirely: LabelTemplate replaces the browse button - here with a full drop-zone panel that hides itself once files are selected - and FileViewTemplate replaces each item of the file list, receiving the file info as its context with its name, size, progress, speed and status all available for rendering. The template is only asked for the files that are actually in the list, so a removed file never leaves an empty item behind. Replacing the browse button also replaces the built-in dashed drop indicator that lives on it, so a custom label should bring its own drag feedback: Classes.Dragging puts a class on the root element for as long as files hover over the component.

Two things are worth carrying over from the default UI when replacing it. The controls should be real button elements rather than clickable divs or icons, so they stay reachable with Tab and can be activated with Enter or Space, and each of them should name the file it acts on through an aria-label - a list of identical "Remove" buttons tells a screen reader user nothing about which file they are on. And since the context is the file itself, the per-file overloads are the ones to call: Upload(file) and RemoveFile(file) act on that one file, while their no-argument forms would sweep through the whole batch.


Public API

The component can be driven entirely from code: Browse opens the file dialog (here the built-in browse button is hidden with HideLabel and replaced by external BitButtons), Upload starts the upload of a specific file or every file, PauseUpload and CancelUpload stop them, RemoveFile removes files, and Reset clears the whole state. Each of them takes a single file or, with no argument, applies to the whole batch. Files exposes the current selection with each file's status and progress, and UploadStatus reports the state of the batch as a whole - pending until the first upload starts, in progress from then on, and completed once every file has reached a terminal state.

The difference between the two ways of stopping is what happens next. PauseUpload applies to the files that are actually on their way: it aborts the in-flight request and keeps the bytes that made it, so calling Upload again resumes from there - from the last completed chunk in the chunked mode - and it takes a file still waiting in the concurrency queue back out of that queue. A file nobody asked to upload has nothing to pause, so it is left exactly as it is.

CancelUpload settles the file as canceled instead, and does so immediately whether it was running, waiting in the queue, paused or merely selected, so the outcome is visible on every file rather than being recorded as an intention on some of them. Files that have already settled are left alone: a completed upload cannot be taken back from the server by anything happening on this side, and calling off a file that already failed would only replace the reason it failed with a less useful one. A canceled file can still be started again later, and its item offers the retry button for exactly that.


Accessibility

The BitFileUpload is accessible out of the box: the browse button is a real button - focusable with Tab and activated with Enter or Space - the hidden native input points to it via aria-labelledby, the file list carries list and listitem roles, every action button (upload, pause, cancel, remove) gets an aria-label naming the file it acts on, and the progress bar exposes its percentage through the progressbar role. A visually hidden live region announces the selection and every upload outcome, so a screen reader user hears how many files were taken, which uploads succeeded and which failed without having to go looking. AnnouncementProvider replaces that built-in English sentence with text of your own - the natural place to translate it or to word it around your domain, as the second example does. AriaLabel labels the browse button, overriding its visible text for assistive technologies when a short label does not say enough on its own.


Variant

The browse button is the visual weight the component carries on a page, and Variant decides how much of it there is. Fill - the default - paints the button in a solid block of the Color and is the right call when uploading is the main thing the screen is for. Outline keeps only the rule around it in that color and fills in on hover, for an uploader sitting among other form fields that should not shout over them. Text drops both the rule and the fill, leaving a colored label for the places where the uploader is a secondary affordance. The drop indicator and the file list follow the variant along, and a disabled component drops the role colors entirely for the neutral disabled look, whichever variant it uses.



Color

Color picks the role color the component speaks in. It is not only the browse button: the dashed drop indicator, the progress bar of every running file, the paused status message, the removal spinner and the hovered action buttons all take it, so the whole control reads as one piece instead of a themed button next to a default-blue list. All the standard bit color roles are available - the semantic ones (Primary, Secondary, Tertiary, Info, Success, Warning, SevereWarning, Error) as well as the background, foreground and border families - each of them carrying its own hover and active shades and its own readable on-color for the label.



Background, foreground and border colors:

External Icons

The action button icons are not limited to the built-in icon font: UploadIcon, RetryIcon, PauseIcon, CancelIcon and RemoveIcon take a BitIconInfo or a raw CSS class string that can point at any icon library whose stylesheet is loaded, like FontAwesome or Bootstrap Icons below. Use BitIconInfo.Fa(), BitIconInfo.Bi() or BitIconInfo.Css() to build one, or stick with the built-in font and just pick different icons via the ...IconName counterparts. Upload a file against a failing endpoint to see the retry icon take the place of the upload one.


FontAwesome:






Bootstrap:



Size

Size scales the whole control in one move - the height, padding and font of the browse button, the text of the file items and their size line, the action buttons and their icons, and the image preview thumbnails all step together, so a Small uploader tucked into a dense form and a Large one headlining a drop area both stay internally proportioned. Medium is the default. The dimensions come from CSS custom properties on the root element, so a size can still be fine-tuned from Styles without redefining the whole scale.



Style & Class

Style and Class land on the root element, which inline styles and a single class cover well. For anything deeper, Styles and Classes reach the individual parts - the browse button, the description, the file list, each file item, its name, size, percentage, progress bar, status message and every action button and icon - and their Dragging entry applies to the root element only while files are being dragged over the component, which is how the examples below restyle the drop state without touching the idle look.


Component's Style & Class:





Styles & Classes:


RTL

Setting Dir to BitDir.Rtl mirrors the whole layout for right-to-left languages - the browse button, the file names, sizes, progress bars and action buttons all follow - and the localizable texts (the Label, the status messages and the button titles) complete the picture, so the BitFileUpload reads naturally inside an RTL page like the Farsi example below.

API

Every parameter, public member, sub-class and enum this component exposes.

BitFileUpload parameters

Name Type Default value Description
Accept string? null Accepted file types for the file browser using MIME types or file extensions (e.g., "image/*", ".pdf,.doc"), applied to the accept attribute of the underlying input element. When not set, the accept attribute is generated from AllowedExtensions.
AllowDrop bool true Whether files can be selected by dragging them from the operating system and dropping them on the component.
AllowDuplicates bool true Whether a file that is already in the file list can be selected again. When disabled, a newly selected file matching an existing one by name, size and last modified time is rejected with the DuplicateErrorMessage instead of being uploaded a second time, becoming eligible again once the file it duplicates is removed.
AllowedExtensions IReadOnlyCollection<string> ["*"] Allowed file types for validation purposes, accepting both file extensions (with an optional leading dot, case-insensitive) and MIME types with an optional wildcard (e.g., "image/*"). Use ["*"] to allow all file types. Files not matching any of these entries will not be uploaded.
AllowPaste bool true Whether files can be selected by pasting them from the clipboard onto the component. The paste is only captured while the focus is inside the component.
AnnouncementProvider Func<IReadOnlyList<BitFileInfo>, string?>? null Custom provider of the text announced by the screen reader through the live region of the component whenever the file list or an upload outcome changes. Receives the current file list and returns the text to announce, or null to announce nothing. When not set, a built-in English announcement is used.
Append bool false Whether a new selection is added to the end of the current file list instead of replacing it, which is what lets the user build a batch up over several rounds of browsing, dropping or pasting. The files already in the list keep their upload state.
AutoChunkSize bool false Calculate the chunk size dynamically based on the user's Internet speed between 512 KB and 10 MB.
AutoReset bool false Whether the file list and the upload state are cleared right before the file dialog opens, so that every browse starts from a clean slate - the list empties even if the dialog is then cancelled.
AutoRetries int 0 The number of times a failed upload of a file gets retried automatically before it is reported as failed. In the chunked mode each retry resumes from the last successfully uploaded chunk. Set to 0 (the default) to disable the automatic retries.
AutoRetryDelay TimeSpan? null The delay before each automatic retry of a failed upload. Set to null (the default) to retry immediately.
AutoUpload bool false Whether the selected files start uploading the moment they are selected, skipping the per-file upload button entirely, for the cases where the selection itself expresses the intent to upload.
CancelButtonTitle string? null The tooltip of the cancel upload button, which is also used as the prefix of its accessible label (e.g., "Cancel report.pdf"). Defaults to "Cancel".
CancelIcon BitIconInfo? null The icon to use for the cancel upload button using custom CSS classes for external icon libraries. Takes precedence over CancelIconName when both are set.
CancelIconName string? null The name of the icon to use for the cancel upload button from the built-in Fluent UI icons. Defaults to Cancel when not set.
CanceledUploadMessage string File upload canceled The message shown for canceled file uploads.
Capture string? null The capture behavior of the file input on devices with a camera or microphone, rendered as the capture attribute of the input element (e.g., "user" for the front camera, "environment" for the rear camera).
ChunkedUpload bool false Whether each file is sliced and sent as a series of sequential requests instead of one monolithic one, which is what makes a paused or failed file resume from the last chunk that made it through rather than starting over, so a dropped connection costs one chunk instead of the whole transfer.
ChunkSize long? null The size in bytes of each chunk of a chunked upload. When not set - and whenever AutoChunkSize is enabled, which takes the decision over - it starts at 512 KB.
Classes BitFileUploadClassStyles? null Custom CSS classes for different parts of the BitFileUpload.
Color BitColor? null The general color of the file upload, applied to the browse button, the drag-and-drop indicator, the progress bars and the hovered action buttons.
ConcurrentUploads int 0 The maximum number of files uploading at the same time, the remaining ones waiting in a queue in selection order and starting as soon as a slot frees up. Set to 0 (the default) to start every file at once.
Description string? null A short hint rendered under the browse button and wired to it through aria-describedby, which is the place to spell out the accepted file types and the size limits so that both sighted and screen reader users learn the constraints before hitting them.
DescriptionTemplate RenderFragment? null Custom Razor template of the hint rendered under the browse button, taking precedence over Description.
Directory bool false Whether to select folders (directories) instead of files, rendered as the webkitdirectory attribute. All files inside the selected folder and its subfolders will be added to the file list. It also makes a dropped folder expand into its contents instead of being ignored.
DuplicateErrorMessage string The file is already selected The message shown for the files rejected for being already in the file list while AllowDuplicates is disabled.
FailedRemoveMessage string File remove failed The message shown for failed file removes.
FailedUploadMessage string File upload failed The message shown for failed file uploads.
FileSizeFormatter Func<long, string>? null Custom formatter of the file size shown under the name of each file item. Receives the size of the file in bytes and returns the text to display, which is the place to localize the units or to switch between the binary and the decimal bases. When not set, a built-in humanizer is used.
FileValidator Func<BitFileInfo, string?>? null Custom validation function called for each newly selected file after the built-in validations pass. Return an error message to reject the file so it will not be uploaded, or null to accept it.
FileViewTemplate RenderFragment<BitFileInfo>? null Custom Razor template rendering each item of the file list in place of the built-in one, receiving the file as its context with its name, size, progress, speed and status all available. It is only asked for the files that are actually in the list, so a removed file leaves no empty item behind.
HideFileView bool false Whether the built-in file list is left unrendered. The files are still selected, validated, uploaded and reported through the Files property and the callbacks - they are simply not drawn, which is what the surrounding page needs when it shows the attachments in a layout of its own.
HideLabel bool false Whether to hide the default browse button label from the UI.
Label string Browse The text of the browse button. Setting it to an empty string hides the button altogether.
LabelTemplate RenderFragment? null Custom Razor template rendered in place of the browse button, which also replaces the built-in dashed drop indicator living on that button - a custom label should bring its own drag feedback through the Dragging entry of Classes or Styles.
MaxCount int 0 Maximum allowed number of files in the file list (0 for unlimited). Files selected beyond this count are rejected at selection time and will not be uploaded. Only files that pass the other validations consume a slot.
MaxCountErrorMessage string The maximum number of files is exceeded Specifies the message shown for the files rejected due to exceeding the maximum number of files.
MaxSize long 0 The maximum allowed size in bytes of each file (0 for unlimited). A larger file is rejected at selection time with the MaxSizeErrorMessage and will not be uploaded.
MaxSizeErrorMessage string The file size is larger than the max size The message shown for the files rejected for being larger than the MaxSize.
MaxTotalSize long 0 Maximum allowed total size in bytes of all the files of the file list (0 for unlimited). Files pushing the accumulated size beyond this limit are rejected at selection time and will not be uploaded, becoming eligible again once removals free up room. Only files that pass the other validations consume the budget.
MaxTotalSizeErrorMessage string The total size of the files is larger than the max total size Specifies the message shown for the files rejected for making the total size of the file list exceed the maximum total size.
MinSize long 0 The minimum allowed size in bytes of each file (0 for no limit). A smaller file is rejected at selection time with the MinSizeErrorMessage and will not be uploaded.
MinSizeErrorMessage string The file size is smaller than the min size The message shown for the files rejected for being smaller than the MinSize.
Multiple bool false Whether several files can be handed over at once, both through the file dialog and through a single drop or paste. Without it a multi-file drop or paste is trimmed down to its first file.
NotAllowedExtensionErrorMessage string The file type is not allowed The message shown for the files rejected for not matching any entry of AllowedExtensions.
OnAllUploadsComplete EventCallback<BitFileInfo[]> Callback for when every file of a batch that actually started uploading has reached a terminal state - completed, failed, canceled, removed or rejected by the validations. A selection that was never asked to upload never settles, so it never reports itself as complete.
OnChange EventCallback<BitFileInfo[]> Callback for when file or files status change. It is invoked with the whole file list right after a selection, and with only the file that changed whenever a single status changes afterwards, so the current state of the batch is better read back from the Files property than from the argument.
OnInvalid EventCallback<BitFileInfo[]> Callback invoked right after OnChange whenever a selection carries at least one file rejected by the validations, providing an array of only the rejected files along with their messages.
OnProgress EventCallback<BitFileInfo> Callback for when the upload of a file makes progress, invoked on every progress report of the browser with the file whose TotalUploadedSize, UploadSpeed and RemainingTime have just moved.
OnRemoveComplete EventCallback<BitFileInfo> Callback for when a file has been removed, whether it was dropped from the list on this side or deleted from the server through the RemoveUrl.
OnRemoveFailed EventCallback<BitFileInfo> Callback for when the removal of a file from the server failed, leaving the file in the list with the FailedRemoveMessage rather than pretending it is gone.
OnUploading EventCallback<BitFileInfo> Callback for when a file upload is about to start, invoked before the request that carries its first byte and therefore once per run of the file rather than once per chunk. It is the place to attach the HttpHeaders and the FormFields that belong to this one file, both of which are read again for every request it makes.
OnUploadComplete EventCallback<BitFileInfo> Callback for when a file has been uploaded successfully, with the body of the server response of its last request on its Message.
OnUploadFailed EventCallback<BitFileInfo> Callback for when the upload of a file failed for good - after the automatic retries, if any, have all been spent - with the body of the failed response on its Message.
PauseButtonTitle string? null The tooltip of the pause upload button, which is also used as the prefix of its accessible label (e.g., "Pause report.pdf"). Defaults to "Pause".
PauseIcon BitIconInfo? null The icon to use for the pause upload button using custom CSS classes for external icon libraries. Takes precedence over PauseIconName when both are set.
PauseIconName string? null The name of the icon to use for the pause upload button from the built-in Fluent UI icons. Defaults to Pause when not set.
QueuedUploadMessage string Waiting to upload The message shown for the files waiting in the queue for a free slot of the ConcurrentUploads limit, which is what tells a file that is about to start apart from one that was never asked to upload.
ReadImageDimensions bool false Whether to read the pixel dimensions of the selected image files, filling the Width and Height of each of them before the validations run, so that a FileValidator can reject an image by its dimensions. Reading them means decoding every image in the browser, which costs time and memory on a large selection, so it is off by default.
RemoveButtonTitle string? null The tooltip of the remove file button, which is also used as the prefix of its accessible label (e.g., "Remove report.pdf"). Defaults to "Remove".
RemoveIcon BitIconInfo? null The icon to use for the remove file button using custom CSS classes for external icon libraries. Takes precedence over RemoveIconName when both are set.
RemoveIconName string? null The name of the icon to use for the remove file button from the built-in Fluent UI icons. Defaults to Delete when not set.
RemoveRequestHttpHeaders Dictionary<string, string>? null Custom HTTP headers attached to the remove request.
RemoveRequestHttpHeadersProvider Func<Task<Dictionary<string, string>>>? null The provider function creating the HTTP headers of the remove request, invoked right before the request goes out and taking precedence over RemoveRequestHttpHeaders.
RemoveRequestHttpMethod string? null The HTTP method of the remove request (e.g., "POST"). Defaults to "DELETE".
RemoveRequestQueryStrings Dictionary<string, string>? null Custom query strings appended to the URL of the remove request.
RemoveRequestQueryStringsProvider Func<Task<Dictionary<string, string>>>? null The provider function creating the query strings of the remove request, invoked right before the request goes out and taking precedence over RemoveRequestQueryStrings.
RemoveUrl string? null URL of the server endpoint removing the files. A file whose bytes already reached the server is deleted from it through a request to this URL carrying its name as a query string and its id in the BIT_FILE_ID header; a file that never uploaded is simply dropped from the list without one.
RetryButtonTitle string? null The tooltip of the retry button of a failed or canceled file, which is also used as the prefix of its accessible label (e.g., "Retry report.pdf"). Falls back to UploadButtonTitle and then to "Retry".
RetryIcon BitIconInfo? null The icon to use for the retry button of a failed or canceled file using custom CSS classes for external icon libraries. Takes precedence over RetryIconName when both are set.
RetryIconName string? null The name of the icon to use for the retry button of a failed or canceled file from the built-in Fluent UI icons. Falls back to UploadIconName and then to Refresh.
ShouldAutoRetry Func<BitFileInfo, int, bool>? null Decides whether a failed upload is worth retrying automatically, receiving the file and the HTTP status code of the failed request (0 for a network error, a timeout or an aborted request) and returning true to spend one of the AutoRetries attempts on it. When not set, a built-in rule retries network errors, timeouts, 408, 429 and the 5xx server errors, and gives up right away on the other 4xx.
ShowPreview bool false Whether a thumbnail of every selected image is shown at the head of its file item, produced entirely in the browser from an object URL that is handed back as soon as the file is removed or the component is reset. The same URL is on the PreviewUrl of each file.
ShowRemoveButton bool false Whether each settled file item offers a remove button, which drops a file that never uploaded from the list and deletes an uploaded one from the server through the RemoveUrl.
Size BitSize? null The size of the file upload, applied to the browse button and the file list items.
Styles BitFileUploadClassStyles? null Custom CSS styles for different parts of the BitFileUpload.
SuccessfulUploadMessage string File upload succeeded The message shown for successful file uploads.
UploadButtonTitle string? null The tooltip of the upload button, which is also used as the prefix of its accessible label (e.g., "Upload report.pdf"). Defaults to "Upload".
UploadFormFieldName string? null The name of the form field carrying the file content in the upload request. Defaults to "file".
UploadIcon BitIconInfo? null The icon to use for the upload button using custom CSS classes for external icon libraries. Takes precedence over UploadIconName when both are set.
UploadIconName string? null The name of the icon to use for the upload button from the built-in Fluent UI icons. Defaults to Play when not set.
UploadRequestFormFields Dictionary<string, string>? null Additional multipart form fields sent alongside the content of every file in its upload requests, for the endpoints that read their metadata from the form rather than from the query string. The FormFields of a file is merged over these for that file.
UploadRequestHttpHeaders Dictionary<string, string>? null Custom HTTP headers attached to the upload requests, fixed at selection time.
UploadRequestHttpHeadersProvider Func<Task<Dictionary<string, string>>>? null The provider function to create the http headers for upload request. Unlike UploadRequestHttpHeaders, it is invoked right before every single request - each file and each chunk - which is what lets it hand over a freshly minted access token.
UploadRequestHttpMethod string? null The HTTP method of the upload request (e.g., "PUT"). Defaults to "POST".
UploadRequestQueryStrings Dictionary<string, string>? null Custom query strings appended to the URL of the upload requests, fixed at selection time.
UploadRequestQueryStringsProvider Func<Task<Dictionary<string, string>>>? null The provider function to create the query strings for upload request. Unlike UploadRequestQueryStrings, it is invoked right before every single request - each file and each chunk - which is what lets it hand over a value that does not survive a batch.
UploadTimeout TimeSpan? null The timeout of the upload request for each file or chunk. When it elapses the upload of the file fails. Set to null (the default) for no timeout.
UploadUrl string? null URL of the server endpoint receiving the files, fixed at selection time. Use UploadUrlProvider instead for an endpoint that has to be minted per request.
UploadUrlProvider Func<Task<string?>>? null The provider function to create the URL of the server endpoint receiving the files. Unlike UploadUrl, it is invoked right before every single request - each file and each chunk - which is what lets it hand over a presigned URL that expires.
Variant BitVariant? null The visual variant of the browse button, which decides how much of the Color it carries: a full fill, only an outline, or neither.
WithCredentials bool false Whether the upload request is sent with credentials such as cookies and authorization headers for cross-origin requests (the withCredentials flag of the underlying XMLHttpRequest).

BitFileUpload public members

Name Type Default value Description
Files IReadOnlyList<BitFileInfo> [] A list of all of the selected files to upload.
UploadStatus BitFileUploadStatus Pending The current status of the file uploader.
InputId string? The id of the file input element.
IsRemoving bool false Indicates that the file upload is in the middle of removing a file.
TotalSize long 0 The total size in bytes of all the files of the batch, excluding the removed ones and the ones rejected by the validations.
TotalUploadedSize long 0 The total uploaded size in bytes across all the files of the batch, excluding the removed ones and the ones rejected by the validations.
OverallUploadProgress int 0 The overall upload progress of the batch as a percentage (0 to 100), combining the progress of all the files weighted by their size.
TotalUploadSpeed double? null The combined speed in bytes per second of every file of the batch that is uploading right now, which is what the connection as a whole is carrying. It is null while nothing is on the wire.
OverallRemainingTime TimeSpan? null The estimated time left before the whole batch is uploaded, derived from the TotalUploadSpeed and the bytes of the batch that are still to be sent. It is null whenever nothing is uploading and the speed is therefore unknown.
Upload (BitFileInfo? fileInfo = null, string? uploadUrl = null) => Task Starts uploading a specific file, or all files when no file is specified, resuming a paused or chunked file from the last chunk that made it through and retrying a failed or canceled one with a fresh budget of automatic retries. A file whose request is already on the wire is left running rather than being started over.
PauseUpload (BitFileInfo? fileInfo = null) => Task Pauses the upload of a specific file, or all files when no file is specified, applying to the files that are on their way: an in-progress file aborts its in-flight request and keeps the bytes that made it, and a file waiting in the concurrency queue is taken out of it. Both can be resumed later through the Upload method. A file that was never asked to upload, and one that has already settled, are left as they are.
CancelUpload (BitFileInfo? fileInfo = null) => Task Cancels the upload of a specific file, or all files when no file is specified, settling every file that is still in play - running, queued, paused or merely selected - as canceled right away and aborting the in-flight request of a running one. A file that has already settled is left alone, and a canceled file can be started again later.
RemoveFile (BitFileInfo? fileInfo = null) => Task Removes a specific file, or all files when no file is specified, deleting the (partially) uploaded ones from the server through the RemoveUrl.
Browse () => Task Opens a file selection dialog.
Reset () => Task Resets the file upload, clearing the file list and the upload state.

BitComponentBase parameters

Name Type Default value Description
AriaLabel string? null Gets or sets the accessible label for the component, used by assistive technologies.
Class string? null Gets or sets the CSS class name(s) to apply to the rendered element.
Dir BitDir? null Gets or sets the text directionality for the component's content.
ForceAnimation bool false Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested.
HtmlAttributes Dictionary<string, object> new Dictionary<string, object>() Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters.
Id string? null Gets or sets the unique identifier for the component's root element.
IsEnabled bool true Gets or sets a value indicating whether the component is enabled and can respond to user interaction.
Style string? null Gets or sets the CSS style string to apply to the rendered element.
TabIndex string? null Gets or sets the tab order index for the component when navigating with the keyboard.
Visibility BitVisibility BitVisibility.Visible Gets or sets the visibility state (visible, hidden, or collapsed) of the component.

BitComponentBase public members

Name Type Default value Description
UniqueId Guid Guid.NewGuid() Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed.
RootElement ElementReference Gets the reference to the root HTML element associated with this component.

BitIconInfo properties

Name Type Default value Description
Name string? null Gets or sets the name of the icon.
BaseClass string? null Gets or sets the base CSS class for the icon. For built-in Fluent UI icons, this defaults to "bit-icon". For external icon libraries like FontAwesome, you might set this to "fa" or leave empty.
Prefix string? null Gets or sets the CSS class prefix used before the icon name. For built-in Fluent UI icons, this defaults to "bit-icon--". For external icon libraries, you might set this to "fa-" or leave empty.

BitFileInfo properties

Name Type Default value Description
ContentType string string.Empty The Content-Type of the selected file.
Name string string.Empty The name of the selected file.
Size long The size of the selected file.
FileId string string.Empty The file ID of the selected file, this is a GUID.
Index int The index of the selected file.
LastModified long The last modified time of the file reported by the browser, in milliseconds since the Unix epoch.
LastModifiedDate DateTimeOffset The last modified time of the file reported by the browser, as a DateTimeOffset.
LastChunkUploadedSize long The size of the last uploaded chunk of the file.
TotalUploadedSize long The total uploaded size of the file.
PreviewUrl string? null An object URL of the file content that can be used as the source of an img element to preview image files. This is only populated for image files when the ShowPreview parameter of the BitFileUpload is enabled.
Width int? null The width of the image in pixels, only populated for decodable image files when the ReadImageDimensions parameter of the BitFileUpload is enabled. It is null for anything else.
Height int? null The height of the image in pixels, only populated for decodable image files when the ReadImageDimensions parameter of the BitFileUpload is enabled. It is null for anything else.
UploadSpeed double? null The observed speed of the upload of this file in bytes per second, measured over the request currently in flight. It is null while the file is not uploading and until the first progress report arrives.
RemainingTime TimeSpan? null The estimated time left before the upload of this file completes, derived from the UploadSpeed and the bytes still to be sent. It is null whenever the speed is unknown.
IsQueued bool false Whether the file is waiting in the upload queue for a free slot of the ConcurrentUploads limit, which is what tells a file that is about to start apart from one that was never asked to upload.
Message string? null The message attached to the current Status of the file: the reason it was rejected by the validations before the upload, or the body of the server response of its upload or removal.
Status BitFileUploadStatus Pending The status of the file in the BitFileUpload.
HttpHeaders Dictionary<string, string>? null Additional custom HTTP headers attached to the upload requests of this specific file (e.g., set from the OnUploading callback).
FormFields Dictionary<string, string>? null Additional multipart form fields sent alongside the content of this specific file in its upload requests, merged over the ones of the UploadRequestFormFields parameter of the BitFileUpload. The natural place to fill it in is the OnUploading callback.

BitFileUploadClassStyles properties

Name Type Default value Description
Root string? null Custom CSS classes/styles for the root element of the BitFileUpload.
Dragging string? null Custom CSS classes/styles for the root element while files are being dragged over the BitFileUpload.
Label string? null Custom CSS classes/styles for the browse button (label) of the BitFileUpload.
Description string? null Custom CSS classes/styles for the description (hint) of the BitFileUpload.
FileList string? null Custom CSS classes/styles for the file list container of the BitFileUpload.
FileItem string? null Custom CSS classes/styles for each file item of the BitFileUpload.
Preview string? null Custom CSS classes/styles for the image preview thumbnail of each file item of the BitFileUpload.
FileName string? null Custom CSS classes/styles for the file name of each file item of the BitFileUpload.
FileSize string? null Custom CSS classes/styles for the file size of each file item of the BitFileUpload.
Percentage string? null Custom CSS classes/styles for the upload percent indicator of each file item of the BitFileUpload.
ProgressBarContainer string? null Custom CSS classes/styles for the progress bar container of each file item of the BitFileUpload.
ProgressBar string? null Custom CSS classes/styles for the progress bar of each file item of the BitFileUpload.
StatusMessage string? null Custom CSS classes/styles for the status message of each file item of the BitFileUpload.
UploadButton string? null Custom CSS classes/styles for the upload button of each file item of the BitFileUpload.
UploadIcon string? null Custom CSS classes/styles for the upload button icon of each file item of the BitFileUpload.
PauseButton string? null Custom CSS classes/styles for the pause button of each file item of the BitFileUpload.
PauseIcon string? null Custom CSS classes/styles for the pause button icon of each file item of the BitFileUpload.
CancelButton string? null Custom CSS classes/styles for the cancel button of each file item of the BitFileUpload.
CancelIcon string? null Custom CSS classes/styles for the cancel button icon of each file item of the BitFileUpload.
RemoveButton string? null Custom CSS classes/styles for the remove button of each file item of the BitFileUpload.
RemoveIcon string? null Custom CSS classes/styles for the remove button icon of each file item of the BitFileUpload.

BitColor enum

Name Value Description
Primary 0 Primary general color.
Secondary 1 Secondary general color.
Tertiary 2 Tertiary general color.
Info 3 Info general color.
Success 4 Success general color.
Warning 5 Warning general color.
SevereWarning 6 SevereWarning general color.
Error 7 Error general color.
PrimaryBackground 8 Primary background color.
SecondaryBackground 9 Secondary background color.
TertiaryBackground 10 Tertiary background color.
PrimaryForeground 11 Primary foreground color.
SecondaryForeground 12 Secondary foreground color.
TertiaryForeground 13 Tertiary foreground color.
PrimaryBorder 14 Primary border color.
SecondaryBorder 15 Secondary border color.
TertiaryBorder 16 Tertiary border color.

BitSize enum

Name Value Description
Small 0 The small size file upload.
Medium 1 The medium size file upload.
Large 2 The large size file upload.

BitVariant enum

Name Value Description
Fill 0 Fill styled variant.
Outline 1 Outline styled variant.
Text 2 Text styled variant.

BitFileUploadStatus enum

Name Value Description
Pending 0 The file is selected and queued, and its uploading has not started yet.
InProgress 1 File uploading is in progress.
Paused 2 File uploading progress is paused by the user.
Canceled 3 File uploading progress is canceled by the user.
Completed 4 The file is successfully uploaded.
Failed 5 The file has a problem and progress is failed.
Removed 6 The uploaded file removed by the user.
RemoveFailed 7 The file removal failed.
NotAllowed 8 The file is rejected by the validations (size, count, type or a custom rule) and will not be uploaded.

BitVisibility enum

Name Value Description
Visible 0 The content of the component is visible.
Hidden 1 The content of the component is hidden, but the space it takes on the page remains (visibility:hidden).
Collapsed 2 The component is hidden (display:none).

BitDir enum

Name Value Description
Ltr 0 Ltr (left to right) is to be used for languages that are written from the left to the right (like English).
Rtl 1 Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic).
Auto 2 Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element.

Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.