private async Task <string> UploadAsync(CommandContext context, AssetFile file)
        {
            string hash;

            using (var hashStream = new HasherStream(file.OpenRead(), HashAlgorithmName.SHA256))
            {
                await assetStore.UploadAsync(context.ContextId.ToString(), hashStream);

                hash = $"{hashStream.GetHashStringAndReset()}{file.FileName}{file.FileSize}".Sha256Base64();
            }

            return(hash);
        }
Ejemplo n.º 2
0
        public async Task EnhanceAsync(Media media, AssetFile file)
        {
            if (media.Type == MediaType.Unknown)
            {
                using (var uploadStream = file.OpenRead())
                {
                    var imageInfo = await assetThumbnailGenerator.GetImageInfoAsync(uploadStream);

                    if (imageInfo != null)
                    {
                        media.Type = MediaType.Image;

                        media.Metadata.SetPixelWidth(imageInfo.PixelWidth);
                        media.Metadata.SetPixelHeight(imageInfo.PixelHeight);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <Media> UploadAsync(string appId, AssetFile file, CancellationToken ct = default)
        {
            Guard.NotNullOrEmpty(appId, nameof(appId));
            Guard.NotNull(file, nameof(file));

            var media = new Media
            {
                AppId    = appId,
                FileName = file.FileName,
                FileSize = file.FileSize,
                MimeType = file.MimeType,
                Metadata = new MediaMetadata()
            };

            foreach (var metadataSource in mediaMetadataSources)
            {
                await metadataSource.EnhanceAsync(media, file);
            }

            var infos = new List <string>();

            foreach (var metadataSource in mediaMetadataSources)
            {
                infos.AddRange(metadataSource.Format(media));
            }

            media.FileInfo = string.Join(", ", infos);

            using (var stream = file.OpenRead())
            {
                await mediaFileStore.UploadAsync(appId, media, stream, ct);
            }

            await mediaRepository.UpsertAsync(media, ct);

            return(media);
        }