public static MediaFile[] GetAssetFiles(StorageBlobClient blobClient, string containerName, string directoryPath, out bool assetStreamable) { assetStreamable = false; List <MediaFile> files = new List <MediaFile>(); CloudBlockBlob[] blobs = blobClient.ListBlobContainer(containerName, directoryPath); foreach (CloudBlockBlob blob in blobs) { string fileName = blob.Name; string fileSize = blobClient.GetBlobSize(containerName, directoryPath, fileName, out long byteCount, out string contentType); MediaFile file = new MediaFile() { Name = fileName, ContentType = contentType, DownloadUrl = blobClient.GetDownloadUrl(containerName, fileName), ByteCount = byteCount, Size = fileSize }; if (file.Name.EndsWith(Constant.Media.Stream.ManifestExtension, StringComparison.OrdinalIgnoreCase)) { assetStreamable = true; } files.Add(file); } return(files.ToArray()); }
public async Task <Asset> CreateAsset(string storageAccount, string assetName, string assetDescription, string assetAlternateId, string fileName) { if (string.IsNullOrEmpty(assetName)) { assetName = Path.GetFileNameWithoutExtension(fileName); } StorageBlobClient blobClient = new StorageBlobClient(this.MediaAccount, storageAccount); string sourceContainer = Constant.Storage.Blob.WorkflowContainerName; string sourceUrl = blobClient.GetDownloadUrl(sourceContainer, fileName); Asset asset = CreateAsset(storageAccount, assetName, assetDescription, assetAlternateId); CloudBlockBlob assetBlob = blobClient.GetBlockBlob(asset.Container, null, fileName); await assetBlob.StartCopyAsync(new Uri(sourceUrl)); return(asset); }
private static string[] GetThumbnailUrls(MediaClient mediaClient, StreamingLocator locator) { List <string> thumbnailUrls = new List <string>(); Asset asset = mediaClient.GetEntity <Asset>(MediaEntity.Asset, locator.AssetName); MediaAsset mediaAsset = new MediaAsset(mediaClient, asset); StorageBlobClient blobClient = new StorageBlobClient(mediaClient.MediaAccount, asset.StorageAccountName); StringComparison stringComparison = StringComparison.OrdinalIgnoreCase; foreach (MediaFile assetFile in mediaAsset.Files) { if (assetFile.Name.StartsWith(Constant.Media.Thumbnail.FileNamePrefix, stringComparison)) { string thumbnailUrl = blobClient.GetDownloadUrl(asset.Container, assetFile.Name, false); thumbnailUrls.Add(thumbnailUrl); } } return(thumbnailUrls.ToArray()); }
public Asset CreateAsset(StorageBlobClient sourceBlobClient, StorageBlobClient assetBlobClient, string storageAccount, string assetName, string assetDescription, string assetAlternateId, string sourceContainer, string[] fileNames) { List <Task> copyTasks = new List <Task>(); if (string.IsNullOrEmpty(assetName)) { assetName = Path.GetFileNameWithoutExtension(fileNames[0]); } Asset asset = CreateAsset(storageAccount, assetName, assetDescription, assetAlternateId); foreach (string fileName in fileNames) { string sourceUrl = sourceBlobClient.GetDownloadUrl(sourceContainer, fileName, false); CloudBlockBlob assetBlob = assetBlobClient.GetBlockBlob(asset.Container, null, fileName); Task copyTask = assetBlob.StartCopyAsync(new Uri(sourceUrl)); copyTasks.Add(copyTask); } Task.WaitAll(copyTasks.ToArray()); return(asset); }
internal static MediaFile[] GetAssetFiles(StorageBlobClient blobClient, string containerName, string directoryPath) { BlobContinuationToken continuationToken = null; List <MediaFile> files = new List <MediaFile>(); CloudBlobContainer blobContainer = blobClient.GetBlobContainer(containerName); do { BlobResultSegment blobList; if (!string.IsNullOrEmpty(directoryPath)) { CloudBlobDirectory blobDirectory = blobContainer.GetDirectoryReference(directoryPath); blobList = blobDirectory.ListBlobsSegmentedAsync(continuationToken).Result; } else { blobList = blobContainer.ListBlobsSegmentedAsync(continuationToken).Result; } foreach (IListBlobItem blobItem in blobList.Results) { string fileName = Path.GetFileName(blobItem.Uri.ToString()); string fileSize = blobClient.GetBlobSize(containerName, directoryPath, fileName, out long byteCount, out string contentType); MediaFile file = new MediaFile() { Name = fileName, Size = fileSize, ByteCount = byteCount, ContentType = contentType, DownloadUrl = blobClient.GetDownloadUrl(containerName, fileName, false) }; files.Add(file); } continuationToken = blobList.ContinuationToken; } while (continuationToken != null); return(files.ToArray()); }