public async Task <ActionResult> Index(HttpPostedFileBase file)
        {
            try
            {
                if (file?.ContentLength > 0)
                {
                    var vPictureName = Guid.NewGuid().ToString();
                    vPictureName += Path.GetExtension(file.FileName);

                    var vRoute = Server.MapPath(serverFolderPath);
                    vRoute = vRoute + "/" + vPictureName;

                    file.SaveAs(vRoute);

                    var vPicture = await vHelper.DetectAndExtracFacesAsync(file.InputStream);

                    vPicture.Name = file.FileName;
                    vPicture.Path = serverFolderPath + "/" + vPictureName;

                    db.EmoPictures.Add(vPicture);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Details", "EmoPictures", new { id = vPicture.Id }));
                }
            }
            catch (Exception exc)
            {
                throw;
            }
            return(View());
        }
        public async Task <ActionResult> Index(HttpPostedFileBase file)
        {
            if (file?.ContentLength > 0)//si no es null y si no es mayo a cero
            {
                try
                {
                    var pictureName = Guid.NewGuid().ToString();
                    pictureName += Path.GetExtension(file.FileName);
                    var route = Server.MapPath(serverFolderPath);
                    route = route + "/" + pictureName;
                    file.SaveAs(route);
                    var emoPicture = await emoHelper.DetectAndExtracFacesAsync(file.InputStream);

                    emoPicture.Name = file.FileName;
                    emoPicture.Path = $"{serverFolderPath}/{pictureName}";
                    db.EmoPictures.Add(emoPicture);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Details", "EmoPictures", new { emoPicture.Id }));
                }
                catch (Exception ex)
                {
                    string message = ex.Message;
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
        public async Task <ActionResult> Index(HttpPostedFileBase file)
        {
            //if(file != null && file.ContentLength > 0)
            if (file?.ContentLength > 0)
            {
                //Cadena aleatoria
                var pictureName = Guid.NewGuid().ToString();
                pictureName += Path.GetExtension(file.FileName);
                //Mapea ruta del servidor a ruta local
                var route = Server.MapPath(serverFolderPath);
                route = route + "/" + pictureName;
                file.SaveAs(route);

                var emoPicture = await emoHelper.DetectAndExtracFacesAsync(file.InputStream);

                emoPicture.Name = file.FileName;
                //Path para la web (relativo)
                //interpolacion de cadenas
                emoPicture.Path = $"{serverFolderPath}/{pictureName}";
                //emoPicture.Path = serverFolderPath + "/" + pictureName;
                //ALmacenar en BD Datacontex?
                db.EmoPictures.Add(emoPicture);
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "EmoPictures", new { Id = emoPicture.Id }));
            }
            return(View());
        }
Example #4
0
        public async Task <IHttpActionResult> PostEmoUploaderAsync(string fileName, Stream file)
        {
            string        key = ConfigurationManager.AppSettings["KEY_EMOTION"];
            string        serverFolderPath = ConfigurationManager.AppSettings["UPLOAD_DIR"];
            EmotionHelper emoHelper        = new EmotionHelper(key);

            var pictureName = Guid.NewGuid().ToString();

            pictureName += Path.GetExtension(fileName);
            var route = System.Web.HttpContext.Current.Server.MapPath(serverFolderPath);

            route += $"/{pictureName}";

            FileStream fileStream = File.Create(route, (int)file.Length);

            byte[] bytesInStream = new byte[file.Length];
            file.Read(bytesInStream, 0, bytesInStream.Length);
            fileStream.Write(bytesInStream, 0, bytesInStream.Length);

            var emoPicture = await emoHelper.DetectAndExtracFacesAsync(file);

            emoPicture.Name = Path.GetFileName(fileName);
            emoPicture.Path = $"{serverFolderPath}/{pictureName}";
            db.EmoPictures.Add(emoPicture);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = emoPicture.Id }, emoPicture));
        }
Example #5
0
        public async Task <ActionResult> Index(HttpPostedFileBase file)
        {
            if (file?.ContentLength > 0)//Si es nulo y mayor que 0
            {
                try
                {
                    var pictureName = Guid.NewGuid().ToString();
                    pictureName += Path.GetExtension(file.FileName);
                    var route = Server.MapPath(serverFolderPath);
                    route += $"/{pictureName}";
                    file.SaveAs(route);
                    var emoPicture = await emoHelper.DetectAndExtracFacesAsync(file.InputStream);

                    emoPicture.Name = Path.GetFileName(file.FileName);
                    emoPicture.Path = $"{serverFolderPath}/{pictureName}";
                    db.EmoPictures.Add(emoPicture);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Details", "EmoPictures", new { Id = emoPicture.Id }));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
            return(View());
        }
Example #6
0
        public async Task <ActionResult> Index(HttpPostedFileBase file)
        {
            if (file?.ContentLength > 0)                         //file != null && file.ContentLength > 0)
            {
                var pictureName = Guid.NewGuid().ToString();     //No se guarda con el Nombre de la imagen porque se puede sobreescribir, se genera un numero aleatorio.
                pictureName += Path.GetExtension(file.FileName); //se obtiene la extension del archivo

                var route = Server.MapPath(serverFolderPath);    //mapea una ruta de servidor a una ruta local
                route = $"{route}\\{pictureName}";
                file.SaveAs(route);

                var emoPicture = await emoHelper.DetectAndExtracFacesAsync(file.InputStream);

                emoPicture.Name = file.FileName;
                emoPicture.Path = $"{serverFolderPath}/{pictureName}";
                db.EmoPictures.Add(emoPicture);
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "EmoPictures", new { Id = emoPicture.Id }));
            }
            return(View());
        }
        public async Task <IHttpActionResult> PostEmoUploader()
        {
            var vHttpRequest = HttpContext.Current.Request;

            foreach (string Archivo in vHttpRequest.Files)
            {
                string PictureFileName = Guid.NewGuid().ToString() + ".jpg";
                var    postedFile      = vHttpRequest.Files[Archivo];
                var    route           = HttpContext.Current.Server.MapPath("~/" + serverFolderPath + "/" + PictureFileName);
                Stream imagens         = postedFile.InputStream;
                postedFile.SaveAs(route);
                var emopicture = await vHelper.DetectAndExtracFacesAsync(imagens);

                emopicture.Name = PictureFileName;
                emopicture.Path = serverFolderPath + "/" + PictureFileName;
                db.EmoPictures.Add(emopicture);
                await db.SaveChangesAsync();

                return(CreatedAtRoute("DefaultApi", new { id = emopicture.Id }, emopicture));
            }

            return(Ok());
        }
Example #8
0
        public async Task <ActionResult> Index(HttpPostedFileBase file)
        {
            if (file?.ContentLength > 0) //file != null && file.ContentLength > 0
            {
                var pictureName = Guid.NewGuid().ToString();
                pictureName += Path.GetExtension(file.FileName);

                var route = Server.MapPath(serverFolderPath);
                route = route + "/" + pictureName;

                file.SaveAs(route);

                var emoPicture = await emoHelper.DetectAndExtracFacesAsync(file.InputStream);

                emoPicture.Nombre = file.FileName;
                emoPicture.Path   = $"{serverFolderPath}/ {pictureName}";

                db.EmoPictures.Add(emoPicture);
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "EmoPictures", new { Id = emoPicture.Id }));
            }
            return(View());
        }