예제 #1
0
 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);
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
        //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);
            }
        }
예제 #4
0
 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);
     }
 }
예제 #5
0
        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");
        }
예제 #6
0
 private void SaveImageChunk(ImageChunk imageChunk)
 {
     _imageChunkSaver.SaveImageChunk(imageChunk, imageChunk.Chunk == 0 ? FileMode.Create : FileMode.Append,
                                     _virtualPathResolver.ResolvePath(_settingRepository.OriginalImageRoot));
 }