遇到的错误: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()); 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 => Console.WriteLine(uri + "\n")); } string storageConnectionString = ConfigurationManager.AppSettings["StorageConnectionString"];
string accountName = ConfigurationManager.AppSettings["AccountName"];
string accountKey = ConfigurationManager.AppSettings["AccountKey"]; /// <summary>
/// 上传blob文件到ams中
/// </summary>
/// <param name="fileName">文件名</param>
public string UploadBlobFile(string fileName)
{
if (string.IsNullOrEmpty(fileName))
return string.Empty;
CloudStorageAccount storageAccount = null;
CloudBlobContainer cloudBlobContainer = null;
if (CloudStorageAccount.TryParse(storageConnectionString, out storageAccount))
{
try
{
// 创建CloudBlobClient,它代表存储帐户的Blob存储端点。
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient(); //fileName = "https://qdlsstorage.blob.core.windows.net/video/20190514165259-魔术视频.mp4";
//通过连接获取容器名字和文件名字
var index = fileName.IndexOf(accountName, StringComparison.CurrentCultureIgnoreCase);
var temp = fileName.Substring(index + );
var fs = temp.Split('/');
var containerName = fs[];
fileName = fs[]; 这一段代码根据你们自己的情况进行修改,我这个是因为传递的全路径才这么写的 // 获取Blob容器
cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
GetCloudMediaContext();
var storageCredentials = new StorageCredentials(accountName, accountKey);
var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(fileName); cloudBlockBlob.FetchAttributes();//这一句是关键,如果不加这一句就会报错,我把报错信息放到下面
var inputAsset = _context.Assets.CreateFromBlob(cloudBlockBlob, storageCredentials, AssetCreationOptions.None);
var strsasUri = PublishAssetGetURLs(inputAsset);
return strsasUri;
}
catch (Exception e)
{
Console.WriteLine(e);
} } return null;
}
}

报错信息:

<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code /><m:message xml:lang="en-US">AssetFile ContentFileSize must not be negative</m:message></m:error>

参考地址:https://github.com/Azure/azure-sdk-for-media-services-extensions/issues/40  (这是通过谷歌找到的资料,百度根本不行)

直接上传文件到资产中调用方法:

                var virtualPath = "/UploadFile/Files/";
var path = HttpContext.Current.Server.MapPath(virtualPath);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var fileFullPath = $"{path}{fileName}";
try
{
file.SaveAs(fileFullPath);
var ams = new AzureMediaServiceController();
url = ams.DeliverVideo(fileFullPath);
result = true;
msg = $@"上传视频成功";
File.Delete(fileFullPath);
}
catch (Exception ex)
{
msg = "上传文件写入失败:" + ex.InnerException + ex.Message + ex.InnerException?.InnerException + "fileFullPath=" + fileFullPath;
}

因为使用的是HTML自带的file上传控件,传递给接口的文件地址全路径是错误的,所以只能保存到接口服务器本地,上传到azure上去之后再删除这个文件。

上传blob到ams

               var ams = new AzureMediaServiceController();
var t = ams.UploadBlobFile(fileUrl);

azure 上传blob到ams(CreateFromBlob)的更多相关文章

  1. 【Azure Developer】VS Code运行Java 版Azure Storage SDK操作Blob (新建Container, 上传Blob文件,下载及清理)

    问题描述 是否可以用Java代码来管理Azure blob? 可以.在代码中加入azure-storage-blob依赖.即可使用以下类操作Azure Storage Blob. BlobServic ...

  2. Windows Azure 上传 VM

    One of the great features of Windows Azure is VHD mobility. Simply put it means you can upload and d ...

  3. ORACEL上传BLOB,深度遍历文件夹

    // uploadingDlg.cpp : 实现文件// #include "stdafx.h"#include "uploading.h"#include & ...

  4. 上传通用化 VHD 并使用它在 Azure 中创建新 VM

    本主题逐步讲解如何使用 PowerShell 将通用化 VM 的 VHD 上传到 Azure.从该 VHD 创建映像,然后从该映像创建新 VM. 可以上传从本地虚拟化工具或其他云导出的 VHD. 对新 ...

  5. Azure Storage 分块上传

    概述 Azure 存储提供三种类型的 Blob:块 Blob.页 Blob 和追加 Blob.其中,块 Blob 特别适用于存储短的文本或二进制文件,例如文档和媒体文件. 块 Blob 由块组成,每个 ...

  6. Azure Blob Storage 基本用法 -- Azure Storage 之 Blob

    Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在<Azure Table storage ...

  7. Azure 基础:Blob Storage

    Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在前文中介绍了 Table Storage 的基本 ...

  8. ueditor使用canvas在图片上传前进行压缩

    之前就看到H5使用canvas就可以在前端使用JS压缩图片,这次接到任务要把这个功能嵌入到ueditor里面去,以节省流量,减轻服务器压力. H5使用canvas进行压缩的代码有很多,核心原理就是创建 ...

  9. 移动前端—H5实现图片先压缩再上传

    在做移动端图片上传的时候,用户传的都是手机本地图片,而本地图片一般都相对比较大,拿iphone6来说,平时拍很多图片都是一两M的,如果直接这样上传,那图片就太大了,如果用户用的是移动流量,完全把图片上 ...

随机推荐

  1. Python实现电子词典

    代码一览: dictionary/├── code│   ├── client.py│   ├── func.py│   ├── server.py│   └── settings.py├── dat ...

  2. NOIP2019翻车前写(and 抄)过的代码

    咕咕咕.按上传时间升序排列. //树的重心 void dfs(int x) { v[x]=1; size[x]=1; int max_part=0; for(int i=hed[x];i;i=nxt[ ...

  3. C语言实现FTP服务器

    公共部分代码 /* common.h */ #ifndef COMMON_H #define COMMON_H #include <arpa/inet.h> #include <ct ...

  4. iptables 的几个状态

    iptables的状态跟踪连接有4种,分别是:NEW.ESTABLISHED.RELATED.INVALID,除了从本机出去的数据包有NAT表的OUTPUT链处理外,其它所有的状态跟踪都在NAT表中的 ...

  5. java信号量

    维基百科解释的信号量概念如下 信号量(英语:semaphore)又称为信号标,是一个同步对象,用于保持在0至指定最大值之间的一个计数值.当线程完成一次对该semaphore对象的等待(wait)时,该 ...

  6. Jmeter实现压力测试(多并发测试)

    一.http://jmeter.apache.org/ 二.点击Download Releases选择版本下载 三.下载解压: 将解压后的文档存盘-下载logkit-2.0.jar(汉化包)放到jme ...

  7. 腾讯云VPS注意事项

    这几天腾讯云VPS搞活动 买了2台服务器, 1台是1核2G1M带宽,一年99 1台是2核4G6M带宽,三年1499 前几年一直在用阿里云,感觉价格太贵,价格上腾讯云,搞活动真的优惠比较大, 最近也准备 ...

  8. 阿里云 azkaban 发邮件的坑

    azkaban : 是一个 任务调度平台 安装文档: https://azkaban.readthedocs.io/en/latest/getStarted.html 因为阿里云是禁止掉是STMP 2 ...

  9. word2vec学习总结

    目录 1.简介 2.从统计语言模型开始 2.1序列概率模型 2.2 N元统计模型 3.深度序列模型 3.1神经概率模型 3.2 one-hot向量表示法 3.3 word2vec 3.4word2ve ...

  10. 【Activiti学习之六】BPMN任务

    环境 JDK 1.8 MySQL 5.6 Tomcat 7 Eclipse-Luna activiti 6.0 一.任务任务表示流程中将要完成的工作. 1.任务继承 2.任务类型Service Tas ...