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

Create Entity and Upload a file at the same time

1 Answer 250 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Veteran
Martin asked on 13 Apr 2021, 02:08 PM

I have just started with Telerik UI for Blazor, using the CoffeHouse demo app.

There is an example using the grid for creating a product and on an existing product upload a document.

I would like to create the product and also upload a file when adding a new product.

The code should first create the product, then upload the filestream.

 

I have a data structure where a user can have many documents. There is a table for the user, the document metadata and a table for the BLOB data.

I have the CRUD working but unable to find a good way to use the grid pop-up together with the upload component

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 14 Apr 2021, 06:25 AM

Hi Martin,

The goal of the TelerikUpload is to provide asynchronous file uploads to an endpoint. How they are associated with code is up to the application  - for example, you can pass metadata from the view-model to the controller through the OnUpload event (see the second snippet).

The Save action for the grid can know where to look for files associated with the current user and their data so it can save them to their final location (NAS, database, user folder, and so on).

Every now and then you can wipe the folder with temp uploads or use a quota for it so that files the users uploaded but didn't save a product for will not fill up the hard drive of the server.

Perhaps when this feature is implemented you will be able to build your own edit form (examples here and here) to start file upload a bit later: https://feedback.telerik.com/blazor/1475230-trigger-file-upload-from-my-own-button. If that is something you would be interested in - Vote for that feature which will raise its priority, and click the Follow button to get status updates. Such a built-in integration will not be possible because the grid can't know you need a special sequence of events, and it can't fire its OnCreate event twice to cater for that.

Something else you may want to consider is a FileSelect type of component - it puts the file in-memory in the blazor app so a byte[] can become part of your model and be saved together with it. It is important to note that this will effectively upload it trough a SignalR connection immediately, so there will still be network traffic, and it will stay in-memory (which may be better or worse for your situation than a file on disk). You can Follow the implementation of a Telerik FileSelect component here: https://feedback.telerik.com/blazor/1460649-fileselect-component. The thread also offers guidance how you can build your own immediately. If that's the approach you would like to take - Vote and Follow that too. A FileSelect component is likely to arrive sooner than the custom upload start above.

Regards,
Marin Bratanov
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

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