How to pass Image by Image to add to the database?

Asked

Viewed 38 times

0

I’m trying to add image to the database, how do I temporarily add object by object up, varying the object according to which index you upload? as I tried to do on line 7

I know there are inconsistencies in the code below, I’m trying to see how to add the images one by one, and then try to solve the rest

I still haven’t fixed all the code the relevant part of line 4 through 9

Controller

       [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "ImagemId,Image,ImagemTipo")]Imagem imagem,List <HttpPostedFileBase> upload)
    {
        List<Imagem> todasImagens;
        int contado = upload.Count;
        for (int x = 0; x < upload.Count;) {
         //parte que eu nao sei como fazer 
         HttpPostedFileBase up = uploa;


        }
        if(upload != null && upload.Count> 0) {
            var arqImagem = new Imagem
            {
                ImagemTipo = upload.ContentType
            };
            using (var reader = new BinaryReader(upload.InputStream))
            {
                arqImagem.Imagem = reader.ReadBytes(upload.ContentLength);
            }
            imagem.Imagem = arqImagem.Imagem;
            imagem.ImagemTipo = arqImagem.ImagemTipo;
        }

             db.Imagens.Add(imagem);
            db.SaveChanges();
        return View(imagem);
    }
  • The code is incomplete friend. Where is the consistency part in the BD? If possible also put the Client class.

  • I couldn’t understand what your doubt is and what mistake you’re getting... the if should not be inside the form and why you store each file in the up and does not use anywhere?]

  • Leandro, referring to the up... was an attempt to resolve, I left to show that I could not.... but the goal is to temporarily up, and up one by one in the database, understood?

No answers

Browser other questions tagged

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