我需要将文件从本地系统上传到azure媒体服务。我已使用HTML5上传器(浏览器块上传)将内容从客户端计算机上传到AMS。参考, http://gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob- 使用共享存取存储签名-HTML和JavaScript的。
现在我需要将上传的文件从blob存储移动到Azure Media Services作为资产并发布。如何实现这一目标。任何人都可以提供这个过程的例子。
答案 0 :(得分:1)
从此链接:Copying an Existing Blob into a Media Services Asset
/// <summary>
/// Creates a new asset and copies blobs from the specifed storage account.
/// </summary>
/// <param name="mediaBlobContainer">The specified blob container.</param>
/// <returns>The new asset.</returns>
static public IAsset CreateAssetFromExistingBlobs(CloudBlobContainer mediaBlobContainer)
{
// Create a new asset.
IAsset asset = _context.Assets.Create("CopyBlob_" + Guid.NewGuid(), AssetCreationOptions.None);
IAccessPolicy writePolicy = _context.AccessPolicies.Create("writePolicy", TimeSpan.FromHours(24), AccessPermissions.Write);
ILocator destinationLocator = _context.Locators.CreateLocator(LocatorType.Sas, asset, writePolicy);
CloudBlobClient destBlobStorage = _destinationStorageAccount.CreateCloudBlobClient();
// Get the asset container URI and Blob copy from mediaContainer to assetContainer.
string destinationContainerName = (new Uri(destinationLocator.Path)).Segments[1];
CloudBlobContainer assetContainer = destBlobStorage.GetContainerReference(destinationContainerName);
if (assetContainer.CreateIfNotExists())
{
assetContainer.SetPermissions(new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
});
}
var blobList = mediaBlobContainer.ListBlobs();
foreach (var sourceBlob in blobList)
{
var assetFile = asset.AssetFiles.Create((sourceBlob as ICloudBlob).Name);
CopyBlob(sourceBlob as ICloudBlob, assetContainer);
assetFile.ContentFileSize = (sourceBlob as ICloudBlob).Properties.Length;
assetFile.Update();
}
destinationLocator.Delete();
writePolicy.Delete();
// Since we copied a set of Smooth Streaming files,
// set the .ism file to be the primary file.
SetISMFileAsPrimary(asset);
return asset;
}