Example #1
0
        public IActionResult PhotoUpload()
        {
            IFormFileCollection files = Request.Form.Files;

            var productId = Convert.ToInt32(Request.Form["prdId"].ToString());

            if (files.Count > 0)
            {
                foreach (var file in files)
                {
                    var randomFileName = RandomValueGenerator.GenerateFileName(Path.GetExtension(file.FileName));


                    string uploadPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/AdminPanelContent/images/ProductPhotos", randomFileName);

                    using (var stream = new FileStream(uploadPath, FileMode.Create))
                    {
                        file.CopyTo(stream);
                    }

                    ProductPhoto photo = new ProductPhoto();
                    photo.ProductId = productId;
                    photo.PhotoPath = "/AdminPanelContent/images/ProductPhotos/" + randomFileName;

                    _productPhotoBs.Insert(photo);
                }
                return(Json(new { IsOk = true }));
            }

            return(Json(new { IsOk = false }));
        }
Example #2
0
        public IActionResult PhotoUpload()
        {
            IFormFileCollection files = Request.Form.Files;

            if (files.Count > 0)
            {
                var fileName    = files[0].FileName;
                var contentType = files[0].ContentType; //MIME Types
                var lenght      = files[0].Length;

                if (!contentType.StartsWith("image/"))
                {
                    return(Json(new { isOk = false, Message = "Lütfen Resim Dosyası Seçiniz" }));
                }

                var randomFileName = RandomValueGenerator.GenerateFileName(Path.GetExtension(fileName));


                string uploadPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/AdminPanelContent/images/ManagerPhotos", randomFileName);

                using (var stream = new FileStream(uploadPath, FileMode.Create))
                {
                    files[0].CopyTo(stream);
                }

                return(Json(new { isOk = true, PhotoPath = "/AdminPanelContent/images/ManagerPhotos/" + randomFileName }));
            }
            else
            {
                return(Json(new { isOk = false, Message = "Lütfen Fotoğraf Seçiniz" }));
            }
        }