Beispiel #1
0
        private AssetStorageMetadata StoreAsset()
        {
            var fileBytes = WebFile.ReadBytes();
            var fileName  = $"original{WebFile.Extension}";

            var storageMetadata = _imageFileRepository.StoreAsset(Id, fileName, WebFile.ContentType, fileBytes);

            return(storageMetadata);
        }
Beispiel #2
0
        private static void UploadAsset(FileMetadata file)
        {
            var assetFileRepository     = new ImageFileRepository();
            var assetDocumentRepository = new AssetDocumentRepository();
            var notifier = new MessageBusClient();

            var assetRootPath = ConfigurationManager.AppSettings["ImageRootPath"];

            var id           = Guid.NewGuid().ToString();
            var fileInfo     = FileReader.GetFileInfo(file.FileLocation);
            var fileContents = FileReader.ReadFile(file.FileLocation);
            var fileName     = $"original{fileInfo.Extension}";


            var storageMetadata = assetFileRepository.StoreAsset(id, fileName, "image/jpeg", fileContents);

            if (storageMetadata == null)
            {
                return;
            }

            var imageMetadata    = FileReader.GetImageMetadata(file.FileName);
            var imageDescription = imageMetadata.GetValue("Exif IFD0", "Image Description");


            var assetMetadata = new AssetMetadata
            {
                Id              = id,
                Name            = file.FileName,
                Description     = imageDescription ?? string.Empty,
                Category        = file.Category,
                ContentType     = "image/jpeg",
                Author          = file.Photographer,
                Url             = $"{assetRootPath}/{storageMetadata.StorageId}",
                StorageMetadata = storageMetadata,
                Type            = "image"
            };

            assetDocumentRepository.Create(assetMetadata);

            notifier.SendMessage(new NewImageAdded {
                ImageName = storageMetadata.StorageId, Id = id
            });
        }
Beispiel #3
0
        private string Generate(StoredAsset originalAsset)
        {
            using (var inputStream = originalAsset.FileStream)
                using (var outputStream = new MemoryStream())
                    using (var factory = new ImageFactory())
                    {
                        factory.Load(inputStream)
                        .Resize(new Size(0, 150))
                        .Format(new JpegFormat()
                        {
                            Quality = 70
                        })
                        .Save(outputStream);

                        var outputBytes = new byte[outputStream.Length];
                        outputStream.Read(outputBytes, 0, (int)outputStream.Length);
                        var thumbnail = _fileRepository.StoreAsset(originalAsset.Id, "thumbnail" + originalAsset.Extension, originalAsset.ContentType,
                                                                   outputBytes);

                        return(thumbnail.StorageLocation);
                    }
        }