public async Task <IFileDescriptor?> AddFileFromStream(Stream file, long size, string fileName, string?defaultfileId = null)
        {
            if (file == null)
            {
                return(null);
            }
            string fileId          = defaultfileId != null ? defaultfileId : Ulid.NewUlid().ToString();
            string contentType     = BlobStorageUtils.GetContentType(fileName);
            var    containerClient = await GetBlobContainerAsync();

            BlobClient blobClient = containerClient.GetBlobClient(fileId);
            // Blob MetaData
            IDictionary <string, string> metadata = new Dictionary <string, string>
            {
                { FileNameMetaDataAttribut, fileName },
            };
            // Blob ContentType
            BlobHttpHeaders blobHeaders = new BlobHttpHeaders()
            {
                ContentType = contentType,
            };

            file.Position = 0;
            await blobClient.UploadAsync(file, blobHeaders, metadata);

            return(new FileDescriptor()
            {
                Id = fileId,
                FileName = fileName,
                Size = size,
                ContentType = contentType
            });
        }
        public async Task <Stream?> GetThumbnailStreamAsync(string fileId, bool fill, int?x, int?y)
        {
            var key             = string.Format("{0}{1}_{2}_{3}", fileId, fill ? "_fill" : "", x, y);
            var containerClient = await GetBlobContainerAsync();

            BlobClient blobClient = containerClient.GetBlobClient(key);

            if (!await blobClient.ExistsAsync())
            {
                var sourceDownloadInfo = await GetFileStreamAsync(fileId);

                if (sourceDownloadInfo == null) // source not found
                {
                    throw new ArgumentException(string.Format("FileId: {0} not found", fileId));
                }
                // create new thumbnail and persist it
                var thumbBitmap = BlobStorageUtils.BuildThumbnailBitmap(sourceDownloadInfo, fill, x, y);
                if (thumbBitmap != null)
                {
                    MemoryStream memoryStream = new MemoryStream();
                    thumbBitmap.Save(memoryStream, ImageFormat.Jpeg);
                    await AddFileFromStream(memoryStream, memoryStream.Length, key, blobClient.Name);

                    memoryStream.Seek(0, SeekOrigin.Begin);
                    return(memoryStream);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                // thumbnail already exists
                var downloadedBlob = await blobClient.DownloadAsync();

                return(downloadedBlob.Value.Content);
            }
        }