public async Task <Response> Handle(Request request, CancellationToken cancellationToken) { var uploadedImage = request.Files.FirstOrDefault(); if (uploadedImage == null || uploadedImage.ContentType.ToLower().StartsWith("image/")) { MemoryStream memoryStream = new MemoryStream(); uploadedImage.OpenReadStream().CopyTo(memoryStream); System.Drawing.Image image = System.Drawing.Image.FromStream(memoryStream); Core.Image imageEntity = new Core.Image() { Id = Guid.NewGuid(), Name = uploadedImage.Name, Data = memoryStream.ToArray(), Width = image.Width, Height = image.Height, ContentType = uploadedImage.ContentType }; _session.Store(imageEntity); _session.SaveChanges(); setId(imageEntity.Id); } return(new Response { ImageId = imageId }); }
public FileStreamResult ViewImage(Guid id) { Core.Image image = _session.Query <Image>().FirstOrDefault(x => x.Id == id); if (image != null) { MemoryStream ms = new MemoryStream(image.Data); return(new FileStreamResult(ms, image.ContentType)); } return(null); }
public bool Save(Core.Image Entity) { try { _dbContext.Images.Add(Entity); return(true); } catch (Exception) { return(false); } }
private void SaveImageMetadata(ImageChunk imageChunk, string uploadedByUsername) { if (imageChunk.Chunk == 0) { var image = new Core.Image { Filename = imageChunk.SystemFilename, SystemFilename = imageChunk.SystemFilename, UploadDate = DateTime.UtcNow, IsPublic = false, ShowOnHomePage = false, Deleted = false, UploadedByUsername = uploadedByUsername }; _imageRepository.Add(image); } }