AstrolUI AstrolUI
Yellow Orange Red Green Blue Purple Custom color
Light mode
UploadFile

1. Demo AstrolUploadFile

Note

In this example, notifications and buttons are implemented, so it is recommended to refer to the respective documentation.


The AstrolUploadFile component provides the logic for browsing files in the explorer, copying and pasting, as well as dragging and dropping files into the defined area. It also allows for deleting uploaded files before they are saved.

@using Astrol.Component.Basic.Button
@using Astrol.Component.Basic.UploadFile
@using Astrol.Entities.Basic.Static.Notification
@using Astrol.Entities.Basic.UI
@using Astrol.JSInterop.Base
@inject AstrolJSInterop jsI
 
<AstrolButton OnClick="_=>ChangeStatus(true)"
              Icon="astrol-upload-cloud"
              Text="Upload file"
              Style="AstrolStyle.Blue" />
<AstrolUploadFile Status="@_statusUpload"
                  SupportedExtensions="@(new List<string> {".jpg",".svg",".png",".pdf",".xlsx"})"
                  Save="SaveFile"
                  OnClose="ChangeStatus" />
<!-- Texts are optional (they follow the app language), e.g. Title="Upload file" TextSave="Save" -->
@code {
   private bool _statusUpload = false;
   private async Task SaveFile(List<IBrowserFile> files) {
       ChangeStatus(false);
       await jsI.Notification($"Attaching {files.Count} file(s).".NotificationSuccess("astrol-upload-cloud", false));
   }
   private void ChangeStatus(bool newStatus) {
       _statusUpload = newStatus;
   }
}

Supported parameters

  • Status (bool), visibility of the upload modal.
  • OnClose (EventCallback<bool>), raised with false when the modal closes (Close button, X, click outside or Esc); update your state variable here.
  • Save (EventCallback<List<IBrowserFile>>), raised when Save is pressed, with the selected files (the button is enabled when there is at least one). The modal does not close by itself: close it in this event. If the event throws, its message is shown as an error notification.
  • Draggable (bool), the modal can be moved (default true).
  • Resizable (bool), the modal can be resized (default false).
  • Outline (bool), outline style for the modal and its buttons (default false).
  • MultipleFile (bool), allows several files; when false, each new file replaces the previous one (default true).
  • MaxNumberOfFiles (int), maximum number of files (default 10).
  • MaxFileSize (long), maximum size per file, in the unit set in TypeStorage (default 5).
  • TypeStorage (TypeStorage), unit of MaxFileSize (default TypeStorage.Megabyte): Byte, Kilobyte, Megabyte, Gigabyte, Terabyte, Petabyte (@using Astrol.Entities.Basic.Enums).
  • SupportedExtensions (List<string>), allowed extensions including the dot (e.g. ".pdf"), case-insensitive; they also filter the file browser. If not set, any file is allowed.
  • IconLoad (string), loading icon (default astrol-spin1).
  • Title, TextClose, TextSave (string), modal title and button texts.
  • TextBrowse (string), drop zone text; TextFileName and TextFileSize (string), name and size labels of each file.
  • TextErrorMaximumNumberFilesAccepted, TextErrorWrongFileExtension, TextErrorFileTooBig (string), error messages.
  • All texts are optional: by default they follow the app language.
  • Besides browsing and drag and drop, files can be pasted (Ctrl+V) into the drop zone.
  • AstrolUploadFileEmbedded: the same drop zone without modal or Save button. It accepts MultipleFile, MaxNumberOfFiles, MaxFileSize, TypeStorage, SupportedExtensions, IconLoad, TextBrowse, TextFileName, TextFileSize and the error texts, plus:
    • OnChange (EventCallback<List<IBrowserFile>>), receives the full list of files every time one is added or removed.
    • CopyZone (ElementReference?), element that receives pastes (defaults to the component itself).

2. Demo AstrolUploadFileEmbedded

@using Astrol.Component.Basic.UploadFile
@using Astrol.Entities.Basic.Static.Notification
@using Astrol.Entities.Basic.Enums
@using Astrol.Entities.Basic.UI
@using Astrol.JSInterop.Base
@inject AstrolJSInterop jsI
 
<AstrolUploadFileEmbedded MaxFileSize="5"
                          TypeStorage="TypeStorage.Megabyte"
                          MaxNumberOfFiles="10"
                          MultipleFile="true"
                          SupportedExtensions="@(new List<string> {".jpg",".png",".svg",".pdf",".xlsx"})"
                          OnChange="OnChange" />
@code {
   private async Task OnChange(List<IBrowserFile> files) {
       await jsI.Notification($"Attaching {files.Count} file(s).".NotificationSuccess("astrol-upload-cloud", false));
   }
}
Markdown for AI © 2026 AstrolUI v10.0.13