Upload
Component for uploading files in Universal Dashboard.
The UDUpload component is used to upload files to Universal Dashboard. You can process files the user uploads. You will receive the data for the file, a file name and the type of file if it can be determined by the web browser.
This component works with UDForm and UDStepper.

Uploading a File

Uploads a file and shows the contents via a toast.
1
New-UDUpload -OnUpload {
2
Show-UDToast $Body
3
}
Copied!
The body of the OnUpload script block is a JSON string with the following format.
1
{
2
data: "base64 encoded string of data",
3
name: "file name of the file uploaded",
4
type: "file type as determined by the browser"
5
}
Copied!

Uploading a File with a Form

Uploads a file as part of a UDForm.
1
New-UDForm -Content {
2
New-UDUpload -Id 'myFile'
3
} -OnSubmit {
4
Show-UDToast $Body
5
}
Copied!
The body of the OnSubmit script block is the same one you will see with any form and the file will be contains as one of the fields within the form.

Example: Uploading a file and save to it the temp directory

This example allows a user to upload a file. Once the file is uploaded, it will be saved to the temporary directory.
1
New-UDUpload -Text 'Upload Image' -OnUpload {
2
$Data = $Body | ConvertFrom-Json
3
$bytes = [System.Convert]::FromBase64String($Data.Data)
4
[System.IO.File]::WriteAllBytes("$env:temp\$($Data.Name)", $bytes)
5
}
Copied!
New-UDUpload
Name
Type
Description
Required
Id
String
The ID of the component. It defaults to a random GUID.
false
Accept
String
The type of files to accept. By default, this component accepts all files.
false
OnUpload
Endpoint
A script block to call when the file is uploaded.
false
Text
String
The text to display in the upload button.
false
Variant
String
The type of button to show for the upload button.
false
Color
String
The color to use for the upload button.
false
Last modified 6mo ago