File upload howto

Anyone have an example of how to upload a CSV?

I have the UDInput loaded and prompting for the file, once selected however nothing happens.

Thanks

I believe Adam said this is coming in the next major version, see here:

Its already in the current version from what I can see in the change logs. I also have it on a page. Just once I select the csv, I don’t know how to process it.

I’m currently playing around now.

I know it’s a few days old this thread but @adamdriscoll was kind enough to upload a youtube video showing just this. So I would recommend looking at Adam Driscolls video on youtube.

maybe this can help you. didn’t find it in the docs either which is a little annoying.

New-UDInput -Title "File Upload" -id "File" -Content {
                New-UDInputField -Type 'file' -Name 'File' -Placeholder 'give me your csv' 
            } -Endpoint {
                param($file)
                    Show-UDToast -Message "$file"
            }
2 Likes

I’ll make sure to get this documented. Sorry about that.

I’ve looked for the video you mentioned, but can’t find it. Can you share the URL?

How do you reference the original file name/extension in the endpoint scriptblock?
It appears that the file contents are correctly passed into the Endpoint block, but I’m not sure how to reference the original file name and extension in the endpoint. In my case, I’m trying to allow the user to upload an image, so i need to know the original file extension in order to save/process the data properly in the endpoint block.

Here’s an example of using the new binaryFile input type. It provides the file name and the 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()
}
2 Likes

That’s perfect. Thanks, Adam!

For those who come across this later, when using type binaryFile, the $File object passed to the Endpoint is of type [Microsoft.AspNetCore.Http.Internal.FormFile]. Properties and methods are documented here: https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.internal.formfile

1 Like

Is there a way currently to filter on specific file types within the New-UDInput binaryFile/file type?

I was able to insert an accept= element in the input field DIV on the running dashboard, but not sure how to incorporate this permanently.

image

Thanks !

Hi @mylabonline,

From what i’m seeing in the code, there isn’t any support added for this yet.
Should however be a small task to add.
Could you create an enhancement request on Github for this?

1 Like

done! thanks.

1 Like

Hi! I’m building a Dashboard that should make me able to upload a firmware.
In short, I’m trying to update HPE iLO firmware, by uploading de .BIN file “somewhere”, so then I can send it to the Server for the upgrade.
It does work if i leave the .BIN file in a certain location and hardcode the location in a variable.

Thanks!