簡體   English   中英

無法上傳到 azure 媒體服務

[英]Unable to upload to azure media service

我一直在嘗試將文件上傳到 Azure 媒體服務器,但我得到的是

Azure 媒體服務終結點 Uri 架構無效

我試過下面的代碼

static void Main(string[] args)
{

    var configuration = new ConfigurationBuilder()
             .AddJsonFile("appsettings.json")
             .Build();
    //_cachedCredentials = new MediaServicesCredentials(_mediaServicesAccountName,
    //_mediaServicesAccountKey);
    //_context = new CloudMediaContext(_cachedCredentials);

    Program program = new Program(configuration);

    //var tokenCredentials1 = new AzureAdTokenCredentials(program._mediaServicesTenant, AzureEnvironments.AzureCloudEnvironment);
    //var tokenProvider1 = new AzureAdTokenProvider(tokenCredentials1);
    //var mediaContext = new CloudMediaContext(new Uri(program._mediaServicesURL), tokenProvider1);
    //mediaContext.Assets.FirstOrDefault();


    AzureAdTokenCredentials tokenCredentials =
               new AzureAdTokenCredentials(program._mediaServicesTenant,
                   new AzureAdClientSymmetricKey(program._mediaServicesClientID, program._mediaServicesClientSecret),
                   AzureEnvironments.AzureCloudEnvironment);

    var tokenProvider = new AzureAdTokenProvider(tokenCredentials);

    //program._mediaServicesURL is "https://management.azure.com/"
    _context = new CloudMediaContext(new Uri(program._mediaServicesURL), tokenProvider);



    IAsset inputAsset = CreateAssetAndUploadSingleFile(@"E:\User\SampleVideo.mp4", AssetCreationOptions.CommonEncryptionProtected);

    //EncodeToAdaptiveBitrateMP4Set(inputAsset);
}
 

 static public IAsset CreateAssetAndUploadSingleFile(string singleFilePath, AssetCreationOptions assetCreationOptions)
{
    if (!File.Exists(singleFilePath))
    {
        Console.WriteLine("File does not exist.");
        return null;
    }

    var assetName = Path.GetFileNameWithoutExtension(singleFilePath);
    //create a new input asset
    IAsset inputAsset = _context.Assets.Create(assetName, assetCreationOptions);

    var assetFile = inputAsset.AssetFiles.Create(Path.GetFileName(singleFilePath));

    Console.WriteLine("Created assetFile {0}", assetFile.Name);

    //create a 30-day read and list access policy
    var policy = _context.AccessPolicies.Create(
    assetName,
    TimeSpan.FromDays(30),
    AccessPermissions.Read | AccessPermissions.List);

    //create a SAS locator to display the asset
    var locator = _context.Locators.CreateLocator(LocatorType.Sas, inputAsset, policy);

    Console.WriteLine("Upload {0}", assetFile.Name);

    assetFile.Upload(singleFilePath);

    Console.WriteLine("Done uploading {0}", assetFile.Name);

    locator.Delete();
    policy.Delete();

    return inputAsset;
}

請幫幫我,我看過很多文章,但運氣不好,如果可能的話,誰能提供完整的上傳工作代碼

看起來您正在使用舊的已棄用 v2 API。這是故意的還是錯誤的? 如果弄錯了,你是怎么到達那里的?

您能否嘗試使用此處示例中的最新 v3 API: https://learn.microsoft.com/en-us/azure/media-services/latest/samples-overview

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM