How do I save an image to the database through an application?

Asked

Viewed 186 times

0

I have an application in c# and I want to make it possible to save a photo in the SQL database. 1- How do I mount the database structure to receive an image? 2- How to send the application photo to the BD?

  • or: https://answall.com/a/202996/69359

1 answer

1

I would recommend saving the photo in some project directory or some ftp.

After saving the way of that photo in the bank, I recently did it. Any doubt just ask

                        //pega o objeto imagem do input front-end
                        HttpPostedFileBase foto = Request.Files["Imagem"];

                        // pega o nome do arquivo
                        var nomeArquivo = Path.GetFileName(foto.FileName);

                        //cria o caminho final da imagem
                        var caminho = Path.Combine(Server.MapPath(Url.Content("~/assets/{nomedapasta}/")), nomeArquivo);

                        //salva a foto no caminho
                        foto.SaveAs(caminho);

                        //imagem do projeto criado recebe o caminho da imagem salva
                        project.Imagem = Path.Combine(Url.Content("/assets/{nomedapasta}/"), nomeArquivo);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.