从另一个blob存储帐户向Media Services提取资产,按照步骤操作 http://social.msdn.microsoft.com/Forums/en-US/MediaServices/thread/9bcaf96d-3a47-4e76-8c95-3bd9200ba432 我的代码是:
CloudStorageAccount storageAccount = Microsoft.WindowsAzure.CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("AzureStorageString"));
private static readonly string _accountName = ConfigurationManager.AppSettings["accountName"];
private static readonly string _accountKey = ConfigurationManager.AppSettings["accountKey"];
public ActionResult UploadData(IEnumerable<HttpPostedFileBase> files)
{
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.GetContainerReference("rawvideos");
if (blobContainer.CreateIfNotExist())
{
blobContainer.SetPermissions(new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
});
}
CloudMediaContext _context = new CloudMediaContext(_accountName, _accountKey);
Guid g = Guid.NewGuid();
IAsset assetToBeProcessed = _context.Assets.CreateEmptyAsset("YourAsset_" + g.ToString(), AssetCreationOptions.None);
IAccessPolicy writePolicy = _context.AccessPolicies.Create("Policy For Copying", TimeSpan.FromMinutes(30), AccessPermissions.Write | AccessPermissions.List);
ILocator destinationLocator = _context.Locators.CreateSasLocator(assetToBeProcessed, writePolicy, DateTime.UtcNow.AddMinutes(-5));
CloudBlobContainer sourceContainer = blobContainer;
CloudBlobContainer destinationContainer= blobClient.GetContainerReference("rawvideocopy");
if (destinationContainer.CreateIfNotExist())
{
blobContainer.SetPermissions(new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
});
}
foreach (var file in files)
{
CloudBlockBlob rawVideoFileRef= blobContainer.GetBlockBlobReference(file.FileName);
rawVideoFileRef.UploadFromStream(file.InputStream);
CloudBlob sourceFileBlob = sourceContainer.GetBlobReference(file.FileName);
sourceFileBlob.FetchAttributes();
long sourceLength = sourceFileBlob.Properties.Length;
CloudBlob destinationFileBlob= destinationContainer.GetBlobReference(file.FileName);
destinationFileBlob.CopyFromBlob(sourceFileBlob);
destinationFileBlob.FetchAttributes();
long destLength = destinationFileBlob.Properties.Length;
assetToBeProcessed.Publish();
assetToBeProcessed = RefreshAsset(_context,assetToBeProcessed);
}
return View();
}
assetToBeProcessed.Publish(); 给出错误:
System.Data.Services.Client.DataServiceQueryException was unhandled by user code
HResult=-2146233079
Message=An error occurred while processing this request.
Source=Microsoft.Data.Services.Client
InnerException: System.Data.Services.Client.DataServiceClientException
HResult=-2146233079
Message=<?xml version="1.0" encoding="utf-8" standalone="yes"?><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><code>Internal Server Error</code><message xml:lang="en-US">Asset has no files uploaded.</message><innererror><message>Asset has no files uploaded.</message><type>System.ArgumentException</type><stacktrace> at Microsoft.Cloud.Media.Vod.Rest.Data.Repository.AssetRepository.InitMainFile(IDataStore dataStore, AssetRecord asset) in d:\Builds\100\IISMediaServices\Release_Official\Sources\Nimbus\Release\src\Vod\Rest\Data\Repository\AssetRepository.cs:line 346
答案 0 :(得分:1)
您需要从目标定位器获取目标文件Blob的URL。