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 {

   $fileStream = [IO.File]::Create($File.FileName)
   $stream = $File.OpenReadStream()

Say I wanted to use this to allow someone to upload a file to then be downloaded by someone else, how might I go about that?

I would suggest using Publish-UDFolder to expose a folder that users can access and doing the above to save the file to that folder. Then you could provide a link to the file via the published folder.

That was my thought. I guess my question then is more of a PowerShell one then actually. I see that the above method puts the file in the write format in the root folder of my dashboard, but I’m unsure how to redirect it to the published folder I have set up.

ah. but I figured it out.

thanks for your help!


Can you post your code, so ppl can learn from it

Of course.

New-Item -Path "$($Cache:RootPath)\share\team\manifest\$_id" -ItemType Directory -Force
$newFilePath = "$($Cache:RootPath)\share\team\manifest\$_id\$($File.FileName)"
$fileStream = [IO.File]::Create($newFilePath)
$stream = $File.OpenReadStream()

Basically I just had to specify the path where I wanted the file to go, rather than just using it’s current path.

1 Like