媒体上传

点播服务端提供丰富的上传接口,支持开发者采用不同的上传方式实现媒体上传。本文介绍.NET SDK调用服务端上传接口的使用场景和调用示例。

使用场景

注意

本文仅提供API调用示例,即在点播服务中获取上传凭证和地址等操作示例。要实现完整的媒体文件上传逻辑,请参考下表跳转至对应的上传方式和使用场景。

接口

使用场景

获取音视频上传地址和凭证

  • OSS原生SDK上传场景下,用户应用服务器集成点播服务端SDK并调用相关接口获取或刷新上传地址和凭证。获取到的上传地址和凭证需要Base64解码后作为初始化OSS上传客户端实例的参数。详情请参见基于OSS原生SDK上传

  • 点播客户端上传SDK场景下,用户应用服务器集成点播服务端SDK并调用相关接口获取或刷新上传地址和凭证。获取到的上传地址和凭证无需解码即可下发给客户端。详情请参见客户端上传SDK指引

刷新音视频上传凭证

获取图片上传地址和凭证

获取辅助媒资上传地址和凭证

URL批量拉取上传

  • 调用URL批量拉取上传接口实现离线拉取上传。这种方式可以免去先将文件下载到本地服务器或终端再使用上传SDK上传到点播的过程。

  • 调用获取URL上传信息获取上传进度。

获取URL上传信息

前提条件

  • 调用接口前请先安装SDK。操作指引请参见安装

  • 调用接口前请先初始化客户端实例。操作指引请参见初始化

    说明

    以下示例均通过AccessKey初始化客户端实例。

接口调用示例

获取音/视频上传地址和凭证

调用CreateUploadVideo接口,完成获取音/视频上传地址和凭证功能。

接口参数和返回字段,请参见CreateUploadVideo。调用示例如下:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.CreateUploadVideo
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                CreateUploadVideoRequest request = new CreateUploadVideoRequest();
                request.Title = "this is a sample title";
                request.FileName = "sample.mp4";
                // request.Tags = "tags1,tags2";
                // request.Description = "this is a sample description";
                //CoverURL示例:http://192.168.0.0/16/sample****.jpg
                // request.CoverURL = "<your Cover URL>";
                // request.CateId = -1;
                // request.TemplateGroupId = "278840921dee4963bb5862b43a52****";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到响应结果
                CreateUploadVideoResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                Console.WriteLine("UploadAddress = " + response.UploadAddress);
                Console.WriteLine("UploadAuth = " + response.UploadAuth);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}
注意

调用CreateUploadVideo接口,生成上传凭证、上传地址和VideoID时,点播控制台视频列表状态显示为上传中,如果客户端后续不进行实际视频上传,或者上传报错,或者是正在上传的时候把上传进程终断了(比如结束App进程),都会导致控制台这个视频状态一直显示为上传中,请调用刷新视频上传凭证接口,传入这个视频ID去获取新的凭证和地址,再去上传,或者手动删除掉这个状态为上传中的视频。更多信息,请参见RefreshUploadVideo(刷新视频上传凭证)。视频实际上传,请调用UploadMediaByURL(URL批量拉取上传)接口。

刷新音/视频上传凭证

调用RefreshUploadVideo接口,完成刷新音/视频上传凭证功能。

接口参数和返回字段请参见RefreshUploadVideo。调用示例如下:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.Sample
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
                request.VideoId = "视频ID";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                RefreshUploadVideoResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                Console.WriteLine("UploadAddress = " + response.UploadAddress);
                Console.WriteLine("UploadAuth = " + response.UploadAuth);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

获取图片上传地址和凭证

调用CreateUploadImage接口,完成获取图片上传地址和凭证功能。

接口参数和返回字段请参见CreateUploadImage。调用示例如下:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.Sample
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                CreateUploadImageRequest request = new CreateUploadImageRequest();
                request.ImageType = "cover";
                request.ImageExt = "jpg";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                CreateUploadImageResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                Console.WriteLine("UploadAddress = " + response.UploadAddress);
                Console.WriteLine("UploadAuth = " + response.UploadAuth);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

获取辅助媒资上传地址和凭证

调用CreateUploadAttachedMedia接口,完成获取辅助媒资上传地址和凭证功能。

接口参数和返回字段请参见CreateUploadAttachedMedia。调用示例如下:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace CreateUploadAttachedMedia
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                CreateUploadAttachedMediaRequest request = new CreateUploadAttachedMediaRequest();
                request.BusinessType = "watermark";
                request.MediaExt = "gif";
                request.Title = "this is a sample";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                CreateUploadAttachedMediaResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                Console.WriteLine("MediaId = " + response.MediaId);
                Console.WriteLine("MediaURL = " + response.MediaURL);
                Console.WriteLine("UploadAddress = " + response.UploadAddress);
                Console.WriteLine("UploadAuth = " + response.UploadAuth);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

URL批量拉取上传

调用UploadMediaByURL接口,完成URL批量拉取上传功能。

接口参数和返回字段请参见UploadMediaByURL。调用示例如下:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.UploadMediaByURL
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                UploadMediaByURLRequest request = new UploadMediaByURLRequest();
                //SourceURL示例:http://192.168.0.0/16/test****.mp4
                request.UploadMetadatas = "[{\"SourceUrl\":\"<your Source URL>\",\"Title\":\"upload by url sample\"}]";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                UploadMediaByURLResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}
阿里云首页 视频点播 相关技术圈