public void SaveImageChunk(ImageChunk imageChunk, FileMode fileMode, string saveDir) { using ( var fs = new FileStream(Path.Combine(saveDir, imageChunk.SystemFilename), fileMode)) { var buffer = new byte[imageChunk.InputStream.Length]; imageChunk.InputStream.Read(buffer, 0, buffer.Length); fs.Write(buffer, 0, buffer.Length); } }
public void ProcessImageChunk(ImageChunk imageChunk, string uploadedByUsername) { if (imageChunk.Chunk == null) imageChunk.Chunk = 0; if (imageChunk.Chunks == null) imageChunk.Chunks = 0; SaveImageMetadata(imageChunk, uploadedByUsername); SaveImageChunk(imageChunk); GenerateMipMaps(imageChunk); }
//TODO: This needs refactoring and test coverage. private void GenerateMipMaps(ImageChunk imageChunk) { if (imageChunk.Chunks == 0 || imageChunk.Chunk == (imageChunk.Chunks - 1)) { ImageCodecInfo info = MipMapGenerator.ProcessCodecs("image/jpeg"); // todo: fix this _mipMapGenerator.GenerateMipMap( Path.Combine(_virtualPathResolver.ResolvePath(_settingRepository.OriginalImageRoot), imageChunk.SystemFilename), new MipMap {Codec = info, Width = 640, Height = 427}, _virtualPathResolver.ResolvePath(_settingRepository.MediumImageRoot), imageChunk.SystemFilename); } }
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); } }
public ActionResult Upload(int? chunk, int? chunks, string name) { var file = Request.Files[0]; if(file == null) { throw new InvalidOperationException("no file process"); } var imageChunk = new ImageChunk { Chunk = chunk, Chunks = chunks, SystemFilename = name, InputStream = file.InputStream }; _imageProcessor.ProcessImageChunk(imageChunk, User.Identity.Name); return Content("chunk uploaded", "text/plain"); }
private void SaveImageChunk(ImageChunk imageChunk) { _imageChunkSaver.SaveImageChunk(imageChunk, imageChunk.Chunk == 0 ? FileMode.Create : FileMode.Append, _virtualPathResolver.ResolvePath(_settingRepository.OriginalImageRoot)); }