Download files uploaded to db with file input

Could someone share with me a sample code or method for downloading files that have been uploaded to a database using the file input? primarily images, pdf, docx.

without the ability to natively download items that have been uploaded, I am finding it hard to see this particular component useful.

Hey @Andrew_Paull,

Just scaffold CRUD pages from our Sample database and check the Product pages. FileInput works with base64 strings and can be used for relatively small size content that can be displayed later inline like the product image. For bigger files you should use RadzenUpload component.

Thanks @enchev!

I created my own method that removes the `"data:image/png;base64" from the database string and converts from Base64 to byte. Thus allowing me to download the file for access in other areas.

Now for the upload component, does that also store the entry in the database in its entirety, or does it require a hosted environment. if stored in the database, what is the storage format?

For anyone else looking for my method, its pretty simple:

            var storedstring = (model.Where(linq_query));
            storedstring = storedstring.Replace("data:image/png;base64,", "");
            byte[] storedbytes = Convert.FromBase64String(storedstring);
            string savefilePath = $"Folder\\";
            string savefileName = $"{savefilePath}\\image.png";
            File.WriteAllBytes(savefileName, storedbytes);

Just replace the generic details with your variables and strings

1 Like