Partage
  • Partager sur Facebook
  • Partager sur Twitter

Upload Image Asp.net API REST

    11 juin 2019 à 19:57:42

    Bonsoir
    J'essai de créer un service ASP.NET API REST upload image qui va me sauvegarder une image dans la base de données,pour consommer le service dans la partie front Angular , mais le service sa marche pas ne s'affiche en SWAGGER  avec les services web que j'ai 
    le code ci-dessous est le service 
    Cordialement
    [HttpPost]
            [Route("api/post/ChmbreImages")]
              FileContentResult PostImage([FromBody] HTL_CHAMBRE chambre)
            {
                using (ReservationBookingEntities1 rbe = new ReservationBookingEntities1())
                {
                    //Depending on if you want the byte array or a memory stream, you can use the below. 
                    var imageDataByteArray = Convert.FromBase64String(chambre.img);
    
                    //When creating a stream, you need to reset the position, without it you will see that you always write files with a 0 byte length. 
                    var imageDataStream = new MemoryStream(imageDataByteArray);
                    imageDataStream.Position = 0;
    
                    //Go and do something with the actual data.
                    //_customerImageService.Upload([...])
    
                    //For the purpose of the demo, we return a file so we can ensure it was uploaded correctly. 
                    //But otherwise you can just return a 204 etc. 
                    return File(imageDataByteArray, "image/png");
                }
            }
    
            private FileContentResult File(byte[] imageDataByteArray, string p)
            {
                throw new NotImplementedException();
            }

    -
    Edité par MoctarTouath 11 juin 2019 à 19:59:55

    • Partager sur Facebook
    • Partager sur Twitter
      14 juin 2019 à 11:50:37

      Déjà, sauvegarder une image dans une DataBase, c'est très moyen comme idée.

      Dans votre code, il n'y rien de tout ce que vous voulez faire.

      Vous semblez avoir pompé le code quelque part mais en commentant "_customerImageService". Pourquoi ne pas chercher à comprendre comment fonctionne votre "source" ???

      • Partager sur Facebook
      • Partager sur Twitter
      Je recherche un CDI/CDD/mission freelance comme Architecte Logiciel/ Expert Technique sur technologies Microsoft.

      Upload Image Asp.net API REST

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown