如何将资产复制到虚拟文件夹
How can I copy an asset to a virtual folder
由于媒体服务不允许我们从流上传并且不允许我们创建虚拟文件夹,我决定将我的图像和视频上传到由虚拟文件夹构成的 blob 容器。
接下来我们需要使用 azure media services face redactor 处理图像和视频。
因此,我们需要将我们的 blob 作为资产复制到 Azure 媒体服务,然后使用面部编辑器,然后我们需要将资产形式的结果上传回其各自的虚拟文件夹。
问题是 Azure 媒体服务不允许我们将资产直接上传到具有特定虚拟路径的另一个容器,或者我认为是这种情况。
如何处理这种情况?
据我所知,特定资产下的资产文件只能在根文件夹下。如果你想将资产文件复制到另一个 blob 容器下的另一个虚拟文件夹,我假设你可以先使用 MediaServices SDK 检索资产,然后你可以使用存储客户端 SDK 检索资产文件并复制到你想要的另一个 blob 容器下的目的地。这是代码片段,您可以参考它:
//retrieve the asset with the specific Id
var asset = _context.Assets.Where(s => s.Id == "nb:cid:UUID:39a13eaf-48cf-4c3c-80d6-bcd6b3b7c8b4").FirstOrDefault();
//retrieve the container name for the current asset
string assetContainerName = asset.Uri.Segments[1];
//construct the CloudBlobClient instance
StorageCredentials mediaServicesStorageCredentials = new StorageCredentials("{storage-name}", "storage-key");
var storageAccount = new CloudStorageAccount(mediaServicesStorageCredentials, true);
var mediaServiceBlobClient = storageAccount.CreateCloudBlobClient();
//construct the CloudBlobContainer instance for the current asset container
var assetContainer = mediaServiceBlobClient.GetContainerReference(assetContainerName);
//define the destination directory under another container
var destDirectory = mediaServiceBlobClient.GetContainerReference("images").GetDirectoryReference("2017/11/7");
//copy the asset files under the current asset container to the specific virtual folder under another blob container
foreach (CloudBlockBlob assetBlob in assetContainer.ListBlobs())
{
var targetBlob = destDirectory.GetBlockBlobReference(assetBlob.Name);
targetBlob.StartCopy(assetBlob);
}
我们的 .Net SDK 确实提供了一些从 Stream 上传的方法(请参阅 this 页面底部附近的最后一个 UploadAsync 重载)。
不过,我们不支持资产中的虚拟目录结构。正如 Bruce Chen 所回应的,您可以使用 Azure 存储 API 在具有虚拟文件夹的 blob 容器和包含 Azure 媒体服务资产的 blob 容器之间来回切换。
要在 .NET Core 中使用 FaceRedactor,请直接使用 REST API 创建具有正确媒体处理器 ID 和配置设置的作业。
https://docs.microsoft.com/en-us/azure/media-services/media-services-face-redaction
curl -X POST\
https://tvmewest.restv2.westcentralus-2.media.azure.net/api/Jobs\
-H 'accept: application/json;odata=verbose' \
-H 'authorization: Bearer 这里是你的 AAD JWT BEARER TOKEN
-H 'cache-control: no-cache' \
-H 'content-type: application/json;odata=verbose' \
-H 'dataserviceversion: 3.0' \
-H 'maxdataserviceversion: 3.0' \
-H 'postman-token: 6662e359-cb76-d849-11c5-99da0514cdc1' \
-H 'user-agent: azure media services postman collection' \
-H 'x-ms-version: 2.15' \
-d'{
"Name": "Redaction Test Job",
"InputMediaAssets":[{
“__metadata”:{
"uri": "https://tvmewest.restv2.westcentralus-2.media.azure.net/api//Assets('\''nb:cid:UUID:733f8d88-f96b-496c-a46e-38c037b89d48'\'')"
}
}],
"Tasks":[{
"Configuration": "{'\''version'\'':'\''1.0'\'', '\''options'\'': {'\''Mode'\'': '\''Combined'\'', '\''BlurType'\'': '\''High'\''}}",
"MediaProcessorId": "nb:mpid:UUID:3806d7a6-4985-4437-b098-50e3733310e8",
"TaskBody":“
作业输入资产(0)
作业输出资产(0)
“
}]
}'
由于媒体服务不允许我们从流上传并且不允许我们创建虚拟文件夹,我决定将我的图像和视频上传到由虚拟文件夹构成的 blob 容器。
接下来我们需要使用 azure media services face redactor 处理图像和视频。
因此,我们需要将我们的 blob 作为资产复制到 Azure 媒体服务,然后使用面部编辑器,然后我们需要将资产形式的结果上传回其各自的虚拟文件夹。
问题是 Azure 媒体服务不允许我们将资产直接上传到具有特定虚拟路径的另一个容器,或者我认为是这种情况。
如何处理这种情况?
据我所知,特定资产下的资产文件只能在根文件夹下。如果你想将资产文件复制到另一个 blob 容器下的另一个虚拟文件夹,我假设你可以先使用 MediaServices SDK 检索资产,然后你可以使用存储客户端 SDK 检索资产文件并复制到你想要的另一个 blob 容器下的目的地。这是代码片段,您可以参考它:
//retrieve the asset with the specific Id
var asset = _context.Assets.Where(s => s.Id == "nb:cid:UUID:39a13eaf-48cf-4c3c-80d6-bcd6b3b7c8b4").FirstOrDefault();
//retrieve the container name for the current asset
string assetContainerName = asset.Uri.Segments[1];
//construct the CloudBlobClient instance
StorageCredentials mediaServicesStorageCredentials = new StorageCredentials("{storage-name}", "storage-key");
var storageAccount = new CloudStorageAccount(mediaServicesStorageCredentials, true);
var mediaServiceBlobClient = storageAccount.CreateCloudBlobClient();
//construct the CloudBlobContainer instance for the current asset container
var assetContainer = mediaServiceBlobClient.GetContainerReference(assetContainerName);
//define the destination directory under another container
var destDirectory = mediaServiceBlobClient.GetContainerReference("images").GetDirectoryReference("2017/11/7");
//copy the asset files under the current asset container to the specific virtual folder under another blob container
foreach (CloudBlockBlob assetBlob in assetContainer.ListBlobs())
{
var targetBlob = destDirectory.GetBlockBlobReference(assetBlob.Name);
targetBlob.StartCopy(assetBlob);
}
我们的 .Net SDK 确实提供了一些从 Stream 上传的方法(请参阅 this 页面底部附近的最后一个 UploadAsync 重载)。
不过,我们不支持资产中的虚拟目录结构。正如 Bruce Chen 所回应的,您可以使用 Azure 存储 API 在具有虚拟文件夹的 blob 容器和包含 Azure 媒体服务资产的 blob 容器之间来回切换。
要在 .NET Core 中使用 FaceRedactor,请直接使用 REST API 创建具有正确媒体处理器 ID 和配置设置的作业。
https://docs.microsoft.com/en-us/azure/media-services/media-services-face-redaction
curl -X POST\ https://tvmewest.restv2.westcentralus-2.media.azure.net/api/Jobs\ -H 'accept: application/json;odata=verbose' \ -H 'authorization: Bearer 这里是你的 AAD JWT BEARER TOKEN -H 'cache-control: no-cache' \ -H 'content-type: application/json;odata=verbose' \ -H 'dataserviceversion: 3.0' \ -H 'maxdataserviceversion: 3.0' \ -H 'postman-token: 6662e359-cb76-d849-11c5-99da0514cdc1' \ -H 'user-agent: azure media services postman collection' \ -H 'x-ms-version: 2.15' \ -d'{ "Name": "Redaction Test Job", "InputMediaAssets":[{ “__metadata”:{ "uri": "https://tvmewest.restv2.westcentralus-2.media.azure.net/api//Assets('\''nb:cid:UUID:733f8d88-f96b-496c-a46e-38c037b89d48'\'')" } }], "Tasks":[{ "Configuration": "{'\''version'\'':'\''1.0'\'', '\''options'\'': {'\''Mode'\'': '\''Combined'\'', '\''BlurType'\'': '\''High'\''}}", "MediaProcessorId": "nb:mpid:UUID:3806d7a6-4985-4437-b098-50e3733310e8", "TaskBody":“ 作业输入资产(0) 作业输出资产(0) “ }] }'