Thursday 6 August 2020

How to upload a file and save in binary format in Asp.net Core

 

Description:

In this example we explain that how to store binary Image in Database in Asp.Net Core. or how to store image in database using .Net Core. So how to save Images to database using Asp.Net Core.

So here we demonstrate that how to upload file and save file n a binary format in database using Asp.Net Core. Below is the code that will help you to save or upload file in database in .net core.


 Code:

[HttpPost]

        public IActionResult Fileuplaod(IFormFile employeephoto)

        {

            long result = 0;

            string employeefileName = string.Empty;

            try

            {

                Byte[] bytes = null;

                if (employeephoto != null)

                {

                    using (MemoryStream ms = new MemoryStream())

 

                    {

 

                        employeephoto.OpenReadStream().CopyTo(ms);

 

                        bytes = ms.ToArray();

 

                    }

                }

               

                result = uplaodfile(bytes); // in this function you can call store procedure to add image in database

              

                    TempData["MsgSuccess"] = _localizer.GetString("Image Uploaded successfully").Value;

 

                return RedirectToAction("Index");

            }

            catch (Exception)

            {

                throw;

            }

        }


This entry was posted in :

0 comments:

Post a Comment