New-UDInputField -Name 'file' -Type file

@adamdriscoll thank you for updating New-UDInputField but can you post an example on how to upload a file and preserve the name.

You can use the new “binaryFile” type to get the file name. When you do this, the parameter passed to you is a IFormFile object. You can then use that object to not only get the file but write binary data.

New-UDInput -Title "Stuff" -Content {
   New-UDInputField -Type binaryFile -Name file 
} -Endpoint {
   param($File)

   $fileStream = [IO.File]::Create($File.FileName)
   $stream = $File.OpenReadStream()
   $stream.CopyTo($fileStream)
   $fileStream.Dispose()
   $stream.Dispose()
}
3 Likes