全部产品

媒体上传

本文档提供了.NET SDK媒体上传相关功能的API调用示例,包含获取上传地址和凭证、注册媒资信息、URL批量拉取上传等。

初始化客户端

使用前请先初始化客户端,请参见初始化

获取视频上传地址和凭证

调用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";
                // request.CoverURL = "http://192.168.0.0/16/sample.jpg";
                // 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());
            }
        }
    }
}

刷新视频上传凭证

调用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();
                request.UploadMetadatas = "[{\"SourceUrl\":\"http://192.168.0.0/16/test.mp4\",\"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());
            }
        }
    }
}

注册媒资信息

调用RegisterMedia接口,完成注册媒资信息功能。

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

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

namespace Aliyun.Acs.vod.Sdk.RegisterMedia
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                RegisterMediaRequest request = new RegisterMediaRequest();
                request.RegisterMetadatas = "[{\"Title\":\"register media test\",\"FileURL\":\"https://test.oss-cn-shanghai.aliyuncs.com/vod-test/aaa.mp4\"}]";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                RegisterMediaResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.RegisteredMediaList != null && response.RegisteredMediaList.Count > 0) {
                    foreach(var media in response.RegisteredMediaList) {
                        Console.WriteLine("MediaId = " + media.MediaId);
                        Console.WriteLine("FileURL = " + media.FileURL);
                        Console.WriteLine("NewRegister = " + media.NewRegister);
                    }
                }
                if (response.FailedFileURLs != null && response.FailedFileURLs.Count > 0) {
                    foreach (var fileURL in response.FailedFileURLs) {
                        Console.WriteLine("FailedFileURL = " + fileURL);
                    }
                }
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}