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

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!

2 Likes

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