public IActionResult Upload([FromServices] IHostingEnvironment environment) { var temp = Request.Form["categoryId"]; IFormFile file = Request.Form.Files["upload_name"]; if (file == null) { return(Content("请选择上传图片")); } string extension = Path.GetExtension(file.FileName), fileName = $"{DateTime.Now.ToString("yyyyMMddHHmmsss")}{extension}", filePath = Path.Combine(environment.WebRootPath, "uploads"), fullPath = Path.Combine(filePath, fileName), vPath = Path.Combine("\\uploads", fileName); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } using (var stream = new FileStream(fullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { file.CopyTo(stream); } int categoryId = Convert.ToInt32(temp.Single()); _service.Add(new ImageEntity { CategoryId = categoryId, FilePath = vPath }); return(Redirect("/admin/image/list")); }
//[Route("Upload")] public async Task <IActionResult> PostImage([FromForm] IFormFile file) { string userId; try { userId = User.Claims.First(c => c.Type == "UserID").Value; } catch { return(Unauthorized()); } var imageName = await _imageFileService.UploadImage(file); if (!"failed".Equals(imageName)) { Photo photo = new Photo() { Name = imageName, Location = _baseUrlHelper.GetBaseUrl() + "/Images/" + imageName, CreateDate = DateTime.Now, ApplicationUserId = userId }; _imageService.Add(photo); _imageService.SaveChanges(); return(Ok(photo)); } else { return(BadRequest(new { message = "Invalid image type!" })); } }
public IActionResult Add([FromBody] ImportImageData data) { try { string fileName = data.ImageFileName; if (string.IsNullOrWhiteSpace(GetContentType(data.ImageFileName))) { throw new Exception("Invalid file type. Only JPEG and PNG files are supported."); } var jBuffer = data.Buffer as Newtonsoft.Json.Linq.JObject; if (null == jBuffer) { throw new Exception("Inbound data is not in the correct format!"); } List <byte> buffer = new List <byte>(); foreach (var item in jBuffer.Children()) { var jProp = item as Newtonsoft.Json.Linq.JProperty; if (null == jProp) { throw new Exception("Inbound data is not in the correct format!"); } buffer.Add((byte)jProp.Value); } imageService.Add(fileName, buffer.ToArray()); return(Json(string.Format("Successfully added {0}", fileName))); } catch (Exception x) { return(Json(new ErrorReport { Error = x.Message })); } }
private async Task <string> TryUpdateImage() { if (goal?.Image != null) { imageService.Remove(goal.Image); } return(await imageService.Add(selectedImageUri, cropView.VisibleRectangleBitmap)); }
public ActionResult CreateImage(int prodId) { ImageViewModel img = new ImageViewModel(); _imageService.Add(img); _productService.SetImage(prodId, img.ImageID); return(View("Images/Create", img)); }
public ActionResult CreateImage(int subcatId) { ImageViewModel img = new ImageViewModel(); _imageService.Add(img); _subcategoryService.SetImage(subcatId, img.ImageID); return(View("Images/Create", img)); }
public IActionResult PostAdd([FromForm] CarImages carImages, [FromForm] IFormFile file) { var result = _ımageService.Add(carImages, file); if (result.Success) { return(Ok()); } return(BadRequest(result)); }
public IActionResult Add([FromForm(Name = "Image")] IFormFile file, [FromForm] Image image) { var result = _imageService.Add(file, image); if (result.Success) { return(Ok(result.Message)); } return(BadRequest(result.Message)); }
public IActionResult Add(Image image) { var result = _imageService.Add(image); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IActionResult InsertImage([FromForm] CarImage carImage, [FromForm(Name = "image")] IFormFile formFile) { var result = _imageService.Add(carImage, formFile); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IActionResult Add([FromForm] Image image, [FromForm] IFormFile file) { var result = _imageService.Add(image, file); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public ActionResult AddItem(ItemViewModel itemViewModel, HttpPostedFileBase uploadImage) { try { itemViewModel.ImageViewModels = _itemService.GetCollectionImages(itemViewModel.Id).MapToCollectionViewModels(); if (ModelState.IsValid) { var itemDto = itemViewModel.MapToDtoModel(); _itemService.Add(itemDto, out int id); _itemCache.Add(itemDto, id); if (uploadImage != null) { itemViewModel.Screen = ImageConvert.ImageToByteArray(uploadImage); itemViewModel.ScreenFormat = ImageConvert.GetImageExtension(uploadImage); var imageVM = new ImageViewModel() { Screen = itemViewModel.Screen, ScreenFormat = itemViewModel.ScreenFormat, ItemId = id }; var imageDto = imageVM.MapToDtoModel(); _imageService.Add(imageDto, out int imageId); } return(RedirectToAction("Index", "User")); } itemViewModel.Statuses = DictionaryOfStatuses(); itemViewModel.Categories = DictionaryOfCategories(); return(View(itemViewModel)); } catch (NotFoundException exception) { ViewBag.ErrorMessage = exception.Message; return(View("NotFound")); } }
public IActionResult Add([FromForm(Name = ("Image"))] IFormFile file, [FromForm] CarImage carImage) { var result = _ImageService.Add(file, carImage); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IActionResult Add([FromForm] IFormFile file, [FromForm] Image carimage) { var result = _imageService.Add(carimage, file); if (result.succces) { return(Ok(result.succces)); } return(BadRequest(result.message)); }
public async Task <IActionResult> CreateImage(List <IFormFile> files) { var response = await _imageService.Add(files); if (response == null) { return(BadRequest(new { message = "File with this name already exists!" })); } return(Ok(new { message = "New image was saved successfuly!" })); }
public async ValueTask <ActionResult <ImageResult> > Upload(IFormFile image) { using (var memoryStream = new MemoryStream()) { await image.CopyToAsync(memoryStream); var imageBytes = memoryStream.ToArray(); var hash = _imageService.Add(imageBytes); return(new ImageResult { Hash = hash }); } }
public Task PrepareAsync(SessionRecording recording) { var images = ExtractImagePaths(recording.Definition.PostSessionSteps) .Concat(ExtractImagePaths(recording.Definition.SessionSteps)) .Concat(ExtractImagePaths(recording.Definition.PostSessionSteps)) .Select(s => s.Trim()) .Distinct(); foreach (var image in images) { _images.Add(image); } return(Task.FromResult(true)); }
private int?AddUserImage(IFormFile imagefile, ApplicationUser user) { var image = _imageService.CreateUserImage(imagefile, user.UserName); if (TryValidateModel(image)) { _imageService.Add(image); var oldimage = _imageService.Find(user.ImageId); if (oldimage != null) { _imageService.Delete(oldimage); } return(image.Id); } return(null); }
public IActionResult Add([FromForm(Name = ("carId"))] int carId) { var checkCount = CheckImageCount(Request.Form.Files); if (checkCount.Success) { var result = _imageService.Add(new ImageDto { CarId = carId, Files = Request.Form.Files }); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); } return(BadRequest(checkCount)); }
public IResult Add(CarImage carImage, IFormFile formFile) { var result = BusinessRules.Run(CheckIfCarImageLimitExceded(carImage.CarId)); if (result != null) { return(new ErrorResult(result.Message)); } var imagePathResult = _imageService.Add(formFile); if (!imagePathResult.Success) { return(new ErrorResult(imagePathResult.Message)); } carImage.ImagePath = imagePathResult.Data; carImage.Date = DateTime.Now; _carImageDal.Add(carImage); return(new SuccessResult(Messages.Success)); }
public async Task <ProfileDto> ChangeImageAsync(string image, User user) { user = await GetAsync(user.Id); string remPhotoId = ""; if (image != null) { remPhotoId = user.PhotoId; user.PhotoId = await _imageService.Add(image); } await _userGR.UpdateAsync(user); if (remPhotoId != null) { await _imageService.Remove(remPhotoId); } return(await GetProfileInfoAsync(user)); }
public ActionResult Add(Image image, string returnUrl = null) { ViewBag.returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var errors = _imageService.ValidateImage(image); if (!errors.Any()) { _imageService.Add(image); if (returnUrl != null) { return(Redirect(returnUrl)); } return(RedirectToAction("Manage")); } ModelState.Merge(errors); } ViewBag.ImageTypes = _imageTypeService.GetAll(); return(View(image)); }
public ActionResult Upload(HttpPostedFileBase uploadImage, int id) { FullVapeDTO fullVapeDto = imageService.GetFullVape(id);//? if (ModelState.IsValid && fullVapeDto != null) { ImageDTO image = new ImageDTO { FullVapeId = id, MimeType = uploadImage.ContentType, }; image.Data = new byte[uploadImage.ContentLength]; uploadImage.InputStream.Read(image.Data, 0, uploadImage.ContentLength); imageService.Add(image); return(View("View")); } else { return(View("View1")); } }
public void Search(ClientEntities.Directory dir) { FileInfo[] files = null; DirectoryInfo[] subDirs = null; DirectoryInfo root = new DirectoryInfo(dir.Path); files = root.GetFiles(); if (files != null) { foreach (FileInfo fi in files) { /// Add to specific list(Casted) String extension = Path.GetExtension(fi.FullName); if (MusicExtensions.Contains(extension)) { musicService.Add(new Music(fi.FullName, fi.Name), dirId); } else if (VideoExtensions.Contains(extension)) { videoService.Add(new Video(fi.FullName, fi.Name), dirId); } else if (PictureExtensions.Contains(extension)) { imageService.Add(new Image(fi.FullName, fi.Name), dirId); } } subDirs = root.GetDirectories(); foreach (DirectoryInfo dirInfo in subDirs) { Search(new ClientEntities.Directory(dirInfo.Name, dirInfo.FullName)); } } }
public static void ImageUpload(IImageService imageService) { var resorce = HostingEnvironment.ApplicationPhysicalPath + GetDefaultImageRootFolder() + "\\data"; var files = Directory.GetFiles(resorce); foreach (var file in files) { var hash = (Guid.NewGuid()).ToString(); var regDate = DateTime.Now; var images = new Image { Name = new FileInfo(file).Name, Hash = hash, CreateDate = regDate }; imageService.Add(images); File.Copy(file, GetImageFilePath(hash, regDate)); } }
public ActionResult CreateImage(ImageViewModel vm) { if (ModelState.IsValid) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var image = vm.ToEntity(); if (vm.Files != null) { var uploadFolderPath = HostingEnvironment.MapPath(string.Concat(SiteConstants.Instance.UploadFolderPath, "Image")); if (!Directory.Exists(uploadFolderPath)) { Directory.CreateDirectory(uploadFolderPath); } foreach (var imageUpload in vm.Files) { if (imageUpload != null) { // If successful then upload image var uploadResult = AppHelpers.UploadFile(imageUpload, uploadFolderPath, LocalizationService); if (!uploadResult.UploadSuccessful) { TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel { Message = uploadResult.ErrorMessage, MessageType = GenericMessages.danger }; unitOfWork.Rollback(); return(Json(new { Result = false, Message = "Vui lòng kiểm tra lại thông tin hình ảnh", }, JsonRequestBehavior.AllowGet)); } image.ImageUrl = uploadResult.UploadedFileName; } } } _imageService.Add(image); try { unitOfWork.Commit(); return(Json(new { Result = true, Message = "Thành công", }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); return(Json(new { Result = false, Message = "Vui lòng kiểm tra lại thông tin hình ảnh", }, JsonRequestBehavior.AllowGet)); } } } else { return(Json(new { Result = false, Message = "Vui lòng kiểm tra lại thông tin hình ảnh", }, JsonRequestBehavior.AllowGet)); } return(View(vm)); }