1

I'm creating an application that uses azure media service. so in order to manage content, I'm trying to upload assets to managed way as below

This was the code I used to create input asset containerPath something like company1/section1

private async Task<Asset> CreateInputAssetAsync(string assetName, string containerPath, IFormFile fileToUpload)
{
    var asset = await _azureMediaServicesClient.Assets.CreateOrUpdateAsync(_appSettings.AzureMediaConfig.ResourceGroup, _appSettings.AzureMediaConfig.AccountName, assetName, new Asset());

    var response = await _azureMediaServicesClient.Assets.ListContainerSasAsync(
        _appSettings.AzureMediaConfig.ResourceGroup, _appSettings.AzureMediaConfig.AccountName,
        assetName,
        permissions: AssetContainerPermission.ReadWrite,
        expiryTime: DateTime.UtcNow.AddHours(4).ToUniversalTime());

    var sasUri = new Uri(response.AssetContainerSasUrls.First());

    var container = new BlobContainerClient(sasUri);
    var blob = container.GetBlobClient(containerPath);

    await blob.UploadAsync(fileToUpload.OpenReadStream());

    return asset;
}

so the creating output asset code

private async Task<Asset> CreateOutputAssetAsync(string containerPath, string assetName)
{
    var outputAsset = await _azureMediaServicesClient.Assets.GetAsync(_appSettings.AzureMediaConfig.ResourceGroup, _appSettings.AzureMediaConfig.AccountName, assetName);
    var asset = new Asset { Container = containerPath };
    var outputAssetName = assetName;

    if (outputAsset != null)
    {
        var uniqueness = $"-{Guid.NewGuid():N}";
        outputAssetName += uniqueness;
    }

    return await _azureMediaServicesClient.Assets.CreateOrUpdateAsync(_appSettings.AzureMediaConfig.ResourceGroup, _appSettings.AzureMediaConfig.AccountName, outputAssetName, asset);
}

But when code runs azure SDK throws an BadRequest exception

What was the missing part in my code

Regards

Gayan
  • 2,750
  • 5
  • 47
  • 88
  • 1
    If my solution inspires or helps you, could you mark my answer as [accepted](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) , Tks~ – Jason Pan Feb 25 '21 at 01:40

1 Answers1

1

UPDATE

If your want use other storage account, you need to Add secondary storage account on portal.

enter image description here

After read .Net SDK, CreateOrUpdateAsync will create a new container. So we just use existed container will solve the issue.

enter image description here

Test Step.

  1. Create new container input and output on portal.

  2. Change your code as below.

     Asset newasset= new Asset();
     newasset.Container = "input";
     newasset.StorageAccountName = "your storage name";
     Asset asset = await client.Assets.CreateOrUpdateAsync(resourceGroupName, accountName, assetName, newasset);
    

Test Result.

enter image description here

enter image description here

enter image description here

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • Okay, Thank you very much for the answer. can you a little bit explain how you manage data with those containers. like in a real scenario I create secondary storage for each company and put all assets under the container. can you look for my workflow and help me to get the solution – Gayan Feb 27 '21 at 14:05