设为首页 加入收藏

TOP

azure 上传blob到ams(CreateFromBlob)(一)
2019-09-17 18:12:25 】 浏览:43
Tags:azure 上传 blob ams CreateFromBlob

遇到的错误:The destination storage credentials must contain the account key credentials,参数名: destinationStorageCredentials

解决方法:AccountName与AccountKey参数值错误

AccountName就是存储账户名字

AccountKey值获取方式:打开存储账户-->访问秘钥-->key1或者key2

Azure上传资产SDK

    public class AzureMediaServiceController : ApiController
    {
        // Read values from the App.config file.

        private static readonly string _AADTenantDomain =
            ConfigurationManager.AppSettings["AMSAADTenantDomain"];
        private static readonly string _RESTAPIEndpoint =
            ConfigurationManager.AppSettings["AMSRESTAPIEndpoint"];
        private static readonly string _AMSClientId =
            ConfigurationManager.AppSettings["AMSClientId"];
        private static readonly string _AMSClientSecret =
            ConfigurationManager.AppSettings["AMSClientSecret"];

        private static CloudMediaContext _context = null;

        [HttpPost, Route("api/AzureMediaService/DeliverVideo")]
        // GET: AMSDeliverVideo
        public string DeliverVideo(string fileName)
        {
            GetCloudMediaContext();
            IAsset inputAsset = UploadFile(fileName, AssetCreationOptions.None);
            var strsasUri = PublishAssetGetURLs(inputAsset);
            return strsasUri;
        }
        /// <summary>
        /// 获取媒体文件上下文
        /// </summary>
        private void GetCloudMediaContext()
        {
            AzureAdTokenCredentials tokenCredentials =
                new AzureAdTokenCredentials(_AADTenantDomain,
                    new AzureAdClientSymmetricKey(_AMSClientId, _AMSClientSecret),
                    AzureEnvironments.AzureCloudEnvironment);

            var tokenProvider = new AzureAdTokenProvider(tokenCredentials);

            _context = new CloudMediaContext(new Uri(_RESTAPIEndpoint), tokenProvider);
        }

        /// <summary>
        /// 创建新资产并上传视频文件
        /// </summary>
        /// <param name="fileName">上传文件名称,如:F:\BigBuck.mp4</param>
        static public IAsset UploadFile(string fileName, AssetCreationOptions options)
        {
            IAsset inputAsset = _context.Assets.CreateFromFile(
                fileName,
                options,
                (af, p) =>
                {
                    Console.WriteLine("Uploading '{0}' - Progress: {1:0.##}%", af.Name, p.Progress);
                });
            return inputAsset;
        }
        static public string PublishAssetGetURLs(IAsset asset)
        {
            // Publish the output asset by creating an Origin locator for adaptive streaming,
            // and a SAS locator for progressive download.
            //用于流媒体(例如 MPEG DASH、HLS 或平滑流式处理)的 OnDemandOrigin 定位符
            //_context.Locators.Create(
            //    LocatorType.OnDemandOrigin,
            //    asset,
            //    AccessPermissions.Read,
            //    TimeSpan.FromDays(30));

            //用于下载媒体文件的访问签名
            _context.Locators.Create(
                LocatorType.Sas,
                asset,
                AccessPermissions.Read,
                TimeSpan.FromDays(30));


            IEnumerable<IAssetFile> mp4AssetFiles = asset
                    .AssetFiles
                    .ToList()
                    .Where(af => af.Name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase));


            // Get the URls for progressive download for each MP4 file that was generated as a result
            // of encoding.
            //List<Uri> mp4ProgressiveDownloadUris = mp4AssetFiles.Select(af => af.GetSasUri()).ToList();
            string mp4ProgressiveDownloadUris = mp4AssetFiles.Select(af => af.GetSasUri()).FirstOrDefault().OriginalString;

            return mp4ProgressiveDownloadUris;
            // Display the URLs for progressive download.   
            // mp4ProgressiveDownloadUris.ForEach(uri => C
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C# 关于爬取网站数据遇到csrf-tok.. 下一篇C# explicit interface implement..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目