All Products
Search
Document Center

Media upload

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see InitVodClient.

Obtain the video upload URL and credential

For more information about the request and response parameters, see 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
            {
                // Constructs a request.
                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://cover.sample.com/sample.jpg";
                // request.CateId = -1;
                // request.TemplateGroupId = "278840921dee4963bb5862b43aeb2273";
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                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());
            }
        }
    }
}

Refresh the video upload credential

For more information about the request and response parameters, see 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
            {
                // Constructs a request.
                RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
                request.VideoId = "Video ID";
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a 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());
            }
        }
    }
}

Obtain the image upload URL and credential

For more information about the request and response parameters, see 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
            {
                // Constructs a request.
                CreateUploadImageRequest request = new CreateUploadImageRequest();
                request.ImageType = "cover";
                request.ImageExt = "jpg";
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a 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());
            }
        }
    }
}

Obtain the upload URL and credential for an attached media asset

For more information about the request and response parameters, see 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
            {
                // Constructs a request.
                CreateUploadAttachedMediaRequest request = new CreateUploadAttachedMediaRequest();
                request.BusinessType = "watermark";
                request.MediaExt = "gif";
                request.Title = "this is a sample";
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a 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());
            }
        }
    }
}

Upload multiple videos based on mezzanine file URLs

For more information about the request and response parameters, see 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://vod.aliyun.com/test.mp4\",\"Title\":\"upload by url sample\"}]";
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a 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());
            }
        }
    }
}

Register media asset information

For more information about the request and response parameters, see 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\"}]";
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a 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());
            }
        }
    }
}