@@ -91,19 +91,21 @@ public async Task<string> CreateMediaInputAsset(IFormFile file)
9191 /// <returns>.</returns>
9292 public async Task < BlobDownloadResult > DownloadMediaInputAsset ( string inputAssetName , string fileName )
9393 {
94- IAzureMediaServicesClient client = await this . CreateMediaServicesClientAsync ( ) ;
94+ var client = this . GetMKIOServicesClientAsync ( ) ;
95+ var assets = client . Assets . Get ( inputAssetName ) ;
96+
97+ BlobServiceClient blobServiceClient = new BlobServiceClient ( this . settings . MediaKindSettings . MediaKindStorageConnectionString ) ;
9598
96- AssetContainerSas assetContainerSas = await client . Assets . ListContainerSasAsync (
97- this . settings . AzureMediaResourceGroup ,
98- this . settings . AzureMediaAccountName ,
99- inputAssetName ,
100- permissions : AssetContainerPermission . Read ,
101- expiryTime : DateTime . UtcNow . AddHours ( 1 ) . ToUniversalTime ( ) ) ;
99+ BlobContainerClient containerClient = blobServiceClient . GetBlobContainerClient ( assets . Properties . Container ) ;
100+ if ( ! await containerClient . ExistsAsync ( ) . ConfigureAwait ( false ) )
101+ {
102+ await containerClient . CreateIfNotExistsAsync ( ) . ConfigureAwait ( false ) ;
103+ }
102104
103- string sasUri = assetContainerSas . AssetContainerSasUrls . First ( ) ;
105+ var filename1 = Regex . Replace ( fileName , "[^a-zA-Z0-9.]" , string . Empty ) ;
106+ filename1 = string . IsNullOrEmpty ( filename1 ) ? "file.txt" : filename1 ;
104107
105- var blobServiceClient = new BlobContainerClient ( new Uri ( sasUri ) ) ;
106- var blobClient = blobServiceClient . GetBlockBlobClient ( fileName ) ;
108+ BlobClient blobClient = containerClient . GetBlobClient ( filename1 ) ;
107109 var fileContent = await blobClient . DownloadContentAsync ( ) ;
108110
109111 return fileContent ;
0 commit comments