How do I save an image in the database through an application? [duplicate]

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 set up the database structure to receive an image? 2 - How will I send the application photo to the DB?

    
asked by anonymous 05.07.2018 / 06:29

1 answer

1

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

After saving the path of that photo in the bank, I recently did this. Any questions 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);
    
06.07.2018 / 04:15