This is a migrated thread and some comments may be shown as answers.

Upload Events

3 Answers 410 Views
Upload
This is a migrated thread and some comments may be shown as answers.
aehlert
Top achievements
Rank 1
Veteran
aehlert asked on 26 Feb 2021, 06:37 PM

For uploads, the examples that are given have the controllers returning an empty results set.

 

Is there an example of returning a custom result set back?

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 26 Feb 2021, 07:01 PM

Hello,

The second example in the OnSuccess handler shows how you can return information form the action (click the Controller tab there): https://docs.telerik.com/blazor-ui/components/upload/events#onsuccess

Here's the gist:

event handler:

    async Task OnSuccessHandler(UploadSuccessEventArgs e)
    {
        Console.WriteLine($"File {e.Files[0].Name} has Status code: {e.Request.Status}, Custom message: {e.Request.ResponseText}");
    }

action:

            return new OkObjectResult("some custom message"); // new OkResult() sends an OK message without custom texts

            //return Content("response message"); // another way to return a custom message

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
aehlert
Top achievements
Rank 1
Veteran
answered on 01 Mar 2021, 12:53 PM

What I'm trying to do is return a filestream and some other values from the upload controller.

In my app, I cannot save the file to disc yet because I do not have the key of the object that I am working with yet.

0
Marin Bratanov
Telerik team
answered on 01 Mar 2021, 02:15 PM

Hi,

I think what you are looking for is a FileSelect for Blazor, you can Follow that here: https://feedback.telerik.com/blazor/1460649-fileselect-component. The thread also offers guidance on how you can build one rather easily with some examples we have in our demos too. There are some more details on this in our previous discussion with you about this last week (link).

We first made a component that solves the much harder task of an actual asynchronous file upload to an endpoint, and for Blazor there is a significant difference, with the file select giving you the files stream or byte[] immediately in your component, as opposed to sending a file to an endpoint for saving. 

An alternative path is to consider returning the path to the file (or other identifier) to the Blazor app from the endpoint. Then the event handler can use this to read the file stream from the server or do any other manipulation it needs with the file that the endpoint already saved - e.g., change its file name, or otherwise modify a database record. The benefit of that is that you may be able to avoid transmitting the file content two times over the wire (can be a massive problem for large files), and there won't be overhead of sending files over the SignalR connection. You could also include that key from the Blazor component together with auth information through the OnUpload event - so that the endpoint has all the info it needs immediately.

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Upload
Asked by
aehlert
Top achievements
Rank 1
Veteran
Answers by
Marin Bratanov
Telerik team
aehlert
Top achievements
Rank 1
Veteran
Share this question
or