【问题标题】:How can I copy an asset to a virtual folder如何将资产复制到虚拟文件夹
【发布时间】:2018-04-19 01:42:44
【问题描述】:

由于媒体服务不允许我们从流上传并且不允许我们创建虚拟文件夹,我决定将我的图像和视频上传到由虚拟文件夹构成的 blob 容器。

接下来我们需要使用 azure media services face redactor 处理图像和视频。

因此,我们需要将我们的 blob 作为资产复制到 azure 媒体服务中,然后使用面部编辑器,然后我们需要将结果以资产的形式上传回其各自的虚拟文件夹。

问题在于 Azure 媒体服务不允许我们将资产直接上传到具有特定虚拟路径的另一个容器,或者我认为是这样。

如何处理这种情况?

【问题讨论】:

    标签: azure asp.net-core azure-storage azure-blob-storage azure-media-services


    【解决方案1】:

    我们的 .Net SDK 确实提供了一些从 Stream 上传的方法(请参阅 this 页面底部附近的最后一个 UploadAsync 重载)。

    不过,我们不支持资产中的虚拟目录结构。正如 Bruce Chen 所回应的那样,您可以使用 Azure 存储 API 在带有虚拟文件夹的 blob 容器和包含 Azure 媒体服务资产的 blob 容器之间来回切换。

    【讨论】:

    • 我正在使用 asp .net 核心。我刚刚遇到一个问题,即 sdk 与 asp .net 核心不兼容。我尝试使用媒体服务 rest api 进行面部修饰,但我找不到。是因为不存在吗?还是我没找到?
    • 我们还没有 .NET Core API。您必须使用 REST API。
    【解决方案2】:

    AFAIK,特定资产下的资产文件只能在根文件夹下。如果您想将资产文件复制到另一个 blob 容器下的另一个虚拟文件夹,我假设您可以先使用 MediaServices SDK 检索资产,然后您可以使用存储客户端 SDK 检索资产文件并复制到您想要的另一个 blob 容器下的目的地。这里是sn-p的代码,大家可以参考一下:

    //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);
    }
    

    【讨论】:

    • 我正在使用 asp .net 核心。我刚刚遇到了媒体服务 sdk 与 asp .net 核心不兼容的问题。我尝试使用媒体服务 rest api 进行面部修饰,但是我找不到面部修饰的 api。是因为不存在吗?还是我没找到?
    • 要从 .NET Core 使用 Face Redactor,您必须按照您的说明包装 REST API。我将在此评论之外粘贴下面的代码
    【解决方案3】:

    要在 .NET Core 中使用 FaceRedactor,请直接使用 REST API 创建具有正确媒体处理器 ID 和配置设置的作业。

    https://docs.microsoft.com/en-us/azure/media-services/media-services-face-redaction

    卷曲-X POST \ https://tvmewest.restv2.westcentralus-2.media.azure.net/api/Jobs\ -H '接受:应用程序/json;odata=verbose' \ -H '授权:Bearer 您的 AAD JWT BEARER TOKEN HERE -H '缓存控制:无缓存' \ -H '内容类型:应用程序/json;odata=verbose' \ -H '数据服务版本:3.0' \ -H '最大数据服务版本:3.0' \ -H '邮递员令牌:6662e359-cb76-d849-11c5-99da0514cdc1' \ -H '用户代理:天蓝色媒体服务邮递员集合' \ -H 'x-ms-版本:2.15' \ -d'{ “名称”:“编辑测试作业”, “输入媒体资产”:[{ “__元数据”:{ "uri": "https://tvmewest.restv2.westcentralus-2.media.azure.net/api//Assets('\''nb:cid:UUID:733f8d88-f96b-496c-a46e-38c037b89d48'\'')" } }], “任务”: [{ "配置": "{'\''版本'\'':'\''1.0'\'', '\''选项'\'': {'\''模式'\'': '\' '组合'\'', '\''BlurType'\'': '\''高'\''}}", "MediaProcessorId": "nb:mpid:UUID:3806d7a6-4985-4437-b098-50e3733310e8", “任务主体”:“ JobInputAsset(0) JobOutputAsset(0) " }] }'

    【讨论】:

    • 如果您想要使用 Postman 集合,请发送电子邮件至 amshelp@microsoft.com。它使生成代码示例变得更加容易。
    猜你喜欢
    • 2012-01-14
    • 2011-05-25
    • 2011-06-25
    • 2011-08-07
    • 2014-09-10
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多