Updated on 2022-12-07 GMT+08:00

Uploads media files to VOD

Function

When calling this API to create a media file, you need to upload the corresponding media file to the OBS bucket of VOD.If the media file to be uploaded is less than 20 MB, you can use the PUT method to upload the media file to the URL returned by the API. For details, see Example 1: Uploading a Media File Less Than 20 MB.If the media file to be uploaded is greater than 20 MB, it must be split into binary streams before being uploaded. For details about how to use this API, see Example 2: Uploading a Media File More Than 20 MB by Part.

URI

POST /v1.0/{project_id}/asset

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

No

String

User token. This parameter is mandatory when token authentication is used.

It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is a token.

Authorization

No

String

Authentication information. This parameter is mandatory for AK/SK authentication.

X-Sdk-Date

No

String

Time when the request is sent. This parameter is mandatory for AK/SK authentication.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

title

Yes

String

Media asset title. The value is UTF-8-encoded and contains a maximum of 128 characters.

description

No

String

Video description. The value contains a maximum of 1024 characters.

video_name

Yes

String

Audio/Video file name. The value contains a maximum of 128 characters.

The file name extension is optional.

video_type

Yes

String

Format of an uploaded media file

Possible values are:

  • Video files: MP4, TS, MOV, MXF, MPG, FLV, WMV, AVI, M4V, F4V, MPEG, 3GP, ASF, and MKV

  • Audio files: MP3, OGG, WAV, WMA, APE, FLAC, AAC, AC3, MMF, AMR, M4A, M4R, WV, and MP2

If an audio file is uploaded, transcoding, watermarking, and subtitling are not supported.

category_id

No

String

Media file category ID

You can call the API for Creating a Media File Category to create a media file category or create a media file category in the category settings on the VOD console and obtain the category ID.

NOTE:

If this parameter is not specified or is set to -1, the uploaded audio/video files fall into the preconfigured Other category.

video_md5

No

String

You are advised to refer to the example of uploading and updating media files in Generating an MD5 Value in the appendix of API Reference.

cover_type

No

String

Thumbnail image format

Possible values are:

  • JPG

  • PNG The name of the uploaded thumbnail is fixed, and the extension is the abbreviation of the thumbnail file format, for example, cover0.jpg and cover1.png. If the file format is not specified, the thumbnail file does not have a file name extension.

NOTE:

If the image format is specified, the first-frame snapshot will not be used as the thumbnail. You need to upload a thumbnail.

cover_md5

No

String

MD5 value of a thumbnail fileYou are advised to refer to the example of uploading and updating media files in Generating an MD5 Value in the appendix of API Reference.

subtitles

No

Array of Subtitle objects

Subtitle file information

tags

No

String

Video tag

Each tag contains up to 16 characters and up to 16 tags are allowed.

Use commas (,) to separate tags. The values are UTF-8-encoded.

auto_publish

No

Integer

Whether to publish the content automatically

Possible values are:

  • 0: The content is not automatically published.

  • 1: The content is automatically published.

Default value: 0

template_group_name

No

String

Name of a transcoding template groupIf this parameter is specified, the specified transcoding template is used to transcode the uploaded audio/video. You can configure a transcoding template on the VOD console. For details, see Transcoding Settings in VOD User Guide.>If both template_group_name and workflow_name are specified, template_group_name takes effect.

auto_encrypt

No

Integer

Whether to automatically encrypt a file

Possible values are:

  • 0: not encrypted

  • 1: encrypted

Default value: 0

A file must be encrypted and transcoded at the same time. When encryption is required, the transcoding parameter cannot be empty and the output file must be in HLS format.

auto_preheat

No

String

Whether to automatically pre-load content to the CDN

Possible values are:

  • 0: The content is not automatically pre-loaded.

  • 1: The content is automatically pre-loaded.

Default value: 0

thumbnail

No

Thumbnail object

Snapshot parameters

review

No

Review object

Media file review parameters

NOTE:

Only the VOD service in the CN North-Beijing1 and CN North-Beijing4 regions supports this function.

workflow_name

No

String

Workflow nameIf this parameter is specified, the specified workflow is used to transcode the uploaded audio/video. You can configure a workflow on the VOD console. For details, see Transcoding Settings in VOD User Guide.

Table 4 Subtitle

Parameter

Mandatory

Type

Description

id

Yes

Integer

Subtitle ID

Value range: 1–8

type

Yes

String

Subtitle file format. Currently, only SRT is supported.

language

Yes

String

Subtitle language

Possible values are:

  • CN: Chinese subtitle

  • EN: English subtitle

md5

No

String

MD5 value of the subtitle file

description

No

String

Subtitle description

Table 5 Thumbnail

Parameter

Mandatory

Type

Description

type

Yes

String

Snapshot capturing mode

Possible values are:

  • time: Snapshots are captured by interval.

  • dots: Snapshots are captured at a specified time point.

time

No

Integer

This parameter is mandatory when type is set to time, indicating that the interval for sampling.

Value range: an integer between 1 and 12

Unit: second

dots

No

Array of integers

This parameter is mandatory when type is set to dots. The array of time points when a snapshot is captured is used.

cover_position

No

Integer

The value indicates which snapshot is specified as the thumbnail.

The default value is 1.

format

No

Integer

Snapshot file format

Possible values are:

  • 1: jpg

The default value is 1.

aspect_ratio

No

Integer

Aspect ratio

Possible values are:

  • 0: adaptive (the original aspect ratio is retained)

  • 1: 16:9

Default value: 0

max_length

No

Integer

The longest side of a snapshot

Unit: pixel

The width of the snapshot is scaled proportionally with the longest side and input video pixel.

Table 6 Review

Parameter

Mandatory

Type

Description

template_id

Yes

String

Review template ID. You can obtain the value after configuring the review template on the VOD console. For details, see Review Settings in VOD User Guide.

NOTE:

Only the VOD service in the CN North-Beijing1 and CN North-Beijing4 regions supports this function.

Response Parameters

Status code: 200

Table 7 Response body parameters

Parameter

Type

Description

asset_id

String

Media ID

video_upload_url

String

URL for uploading videos

cover_upload_url

String

URL for uploading covers

subtitle_upload_urls

Array of strings

Array in the URL for uploading subtitles

target

File_addr object

API for querying media file storage parameters. There is response only when the media file is hosted.

Table 8 File_addr

Parameter

Type

Description

bucket

String

OBS bucket name

location

String

Name of the region where the bucket is located. For example, the region name of CN North-Beijing4 is cn-north-4. The created bucket must be in the region of the VOD service.

object

String

File path

Status code: 403

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Error code

error_msg

String

Error description

Example Requests

POST https://{endpoint}/v1/{project_id}/asset

{
  "title" : "Avatar test test",
  "description" : "Avatar, test",
  "category_id" : -1,
  "tags" : "mytags",
  "video_name" : "Avatar_480P.mp4",
  "video_type" : "MP4",
  "video_md5" : "a945d4b3d8fc317190a9332fe856f03d",
  "cover_type" : "JPG",
  "cover_md5" : "a655d4b3d8fc758691a9332fe387f26c",
  "auto_publish" : 0,
  "subtitles" : [ {
    "id" : 1,
    "language" : "CN",
    "type" : "SRT",
    "md5" : "SqcyFjJZoDZaP8oKIY6rgQ==",
    "description" : "AAAAA"
  } ]
}

Example Responses

Status code: 200

The information is returned when the request succeeds.

{
  "asset_id" : "f488337c31c8e4622f1590735b134c65",
  "video_upload_url" : "https://obs.cn-north-4.myhuaweicloud.com:443/obs-vod-1/%7Bproject_id%7D/f488337c31c8e4622f1590735b134c65/Avatar_480P.mp4?AWSAccessKeyId=CBN2JOVSQVVUREU0RCSN&Expires=1518147618&Signature=kZYh0hEos2VJhjjdHC2zVAHGyXA%3D",
  "cover_upload_url" : "https://obs.cn-north-4.myhuaweicloud.com:443/obs-vod-1/%7Bproject_id%7D/f488337c31c8e4622f1590735b134c65/cover/Cover0.jpg?AWSAccessKeyId=CBN2JOVSQVVUREU0RCSN&Expires=1518147619&Signature=eVoLA54Qi6cG9vZbS3fuaIw1RDQ%3D",
  "subtitle_upload_urls" : [ "https://obs-vod-1.obs.cn-north-4.myhuaweicloud.com:443/14ce1d4437164aba8b364ce15866154e/53a018d2dc53ca07eb5a07a839205c9d/subtitle/1.srt?AWSAccessKeyId=CBN2JOVSQVVUREU0RCSN&Expires=1534760131&Signature=twZPabMSf%2FO%2B2H3mpo3Gsqk1uIo%3D" ],
  "target" : {
    "bucket" : "obs-vod-1",
    "location" : "cn-north-4",
    "object" : "093bb6b6c4fc460ab90a40d8b821dda3/a2053aef99725711dad3e02dc6cd5f89/0a9b70035b78b8a19c6d9e7c2693d93c.mp4"
  }
}

Status code: 403

The information is returned when the request fails.

{
  "error_code" : "VOD.10064",
  "error_msg" : "Media asset classification does not exist, please check."
}

Status Codes

Status Code

Description

200

The information is returned when the request succeeds.

403

The information is returned when the request fails.

Error Codes

See Error Codes.