Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Video On Demand/ API Reference/ Application Examples/ Example 1: Uploading a Media File Less Than 20 MB

Example 1: Uploading a Media File Less Than 20 MB

Updated on 2024-12-04 GMT+08:00

Scenario

If you need to process (such as publish and transcode) your local media files in VOD, then you can call VOD APIs and OBS APIs to upload them to OBS buckets owned by VOD.

This section describes how to upload a video file less than 20 MB by calling APIs.

Prerequisites

  • You have specified the region where the VOD service for uploading media assets is located. See Before You Start.
  • You have obtained the ID of the project by referring to Obtaining a Project ID.

Overall Process

Figure 1 Media asset upload process
  1. Call the API for uploading media assets to VOD to create a media asset.
  2. Upload a local media asset using PUT.
  3. Call the API for confirming media asset upload.

Procedure

  1. Obtain a user token and use it to authenticate the calling of VOD APIs.

    For details, see Making an API Request. CN North-Beijing4 is used as an example. If you need to call a VOD API in another region, replace the endpoint with the IAM endpoint of the corresponding region.

    POST https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens
    Content-Type: application/json
    
    {
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "username", 
              "password": "password", 
              "domain": {
                "name": "domainname"   
              }
            }
          }
        },
        "scope": {
          "project": {
             "name": "projectname"
          }
        }
      }
    }
    As shown in Figure 2, information in the red box indicates the user token.
    Figure 2 Obtaining the user token

  2. Call the API for uploading media assets to VOD to create a media asset. Add the X-Auth-Token field to the request header. The value of Value is obtained in 1.

    POST https://vod.cn-north-4.myhuaweicloud.com/v1.0/{project_id}/asset
    
    {
    	"title": "test",
    	"description": "test",
    	"category_id": 87748, 
    	"video_name": "test.mp4",
    	"video_type": "MP4",
    	"cover_type": "PNG",
    	"tags":"mytags,test",
    	"auto_publish": 0,    
    	"template_group_name":"test",
    	"subtitles":[      
    		{	
    			"id":1,
    			"language":"CN", 
    			"type": "SRT", 
    			"md5": "SqcyFjJZoDZaP8oKIY6rgQ==",    
    			"description":"AAAAA" ,
    			"name":"cc.srt"
    		}  
    	],
    	"thumbnail":{
    		"type":"time",
    		"cover_position":1
    	
    	},
    	"review":{
    		"interval":10,
    		"politics":-1,
    		"terrorism":-1,
    		"porn":-1
    	}	
    }
    • vod.cn-north-4.myhuaweicloud.com is the endpoint of VOD. You can obtain the endpoint from Before You Start.
    • category_id indicates the media asset category ID. You need to create a media category in advance by referring to Creating a Media Asset Category.
    • template_group_name indicates the transcoding template group name. You need to customize a transcoding template in advance by referring to Customizing a Transcoding Template.
      NOTE:

      The region where an IAM API is called must be the same as the region where a VOD API is called. For example, the user token obtained when you call an IAM API in the CN North-Beijing4 region can only be used to authenticate the requests for calling VOD APIs in the CN North-Beijing4 region.

  3. Obtain the values of video_upload_url, cover_upload_url, and subtitle_upload_urls from the response parameters.

    {
      "asset_id": "3f40a2c7c60454f5f84381e0313ca230",
      "video_upload_url": "https://vod-bucket-81.obs.cn-north-4.myhuaweicloud.com:443/474bcff2992f4be5b883a2fb9cec7343/3f40a2c7c60454f5f84381e0313ca230/cdeda86cd1b7b3dd760a3ff28a5ee497.mp4?AWSAccessKeyId=BG923RWHL4HFXOGKCVAL&Expires=1560420274&Signature=9f%2BZcdD6SwjIU5ARHYiP6YY1Lyw%3D",
      "cover_upload_url": "https://vod-bucket-81.obs.cn-north-4.myhuaweicloud.com:443/474bcff2992f4be5b883a2fb9cec7343/3f40a2c7c60454f5f84381e0313ca230/cover/Cover0.png?AWSAccessKeyId=BG923RWHL4HFXOGKCVAL&Expires=1560420274&Signature=4Aa88NK%2By%2By1Xo0RvLpOvuaFCoE%3D",
      "subtitle_upload_urls": [
        "https://vod-bucket-81.obs.cn-north-4.myhuaweicloud.com:443/474bcff2992f4be5b883a2fb9cec7343/3f40a2c7c60454f5f84381e0313ca230/subtitle/1.srt?AWSAccessKeyId=BG923RWHL4HFXOGKCVAL&Expires=1560420274&Signature=l0UclE9yfaVrxkl0kaNnr%2BemG98%3D"
      ],
      "target": {
        "bucket": "vod-bucket-81",
        "location": "cn-north-4",
        "object": "474bcff2992f4be5b883a2fb9cec7343/3f40a2c7c60454f5f84381e0313ca230/cdeda86cd1b7b3dd760a3ff28a5ee497.mp4"
      }
    }

  4. Send PUT requests to upload media assets, thumbnails, and subtitle files to video_upload_url, cover_upload_url, and subtitle_upload_urls.

    Set Content-Type based on the type of the file to be uploaded.
    • Video file: video/video format, for example, video/mp4. For details about how to fill in the request header of a video file format, see Table 1.
    • Audio file: audio/audio format, for example, audio/mp3. For details about how to fill in the request header of an audio file format, see Table 2.
    • Image file: image/image format, for example, image/png.
    • Subtitle file: application/octet-stream
    Table 1 Parameters in the request header of a video file

    File Name Extension

    Content-Type

    MP4

    video/mp4

    MOV

    video/quicktime

    MXF

    application/mxf

    TS

    video/mp2t

    MPG

    video/mpeg

    FLV

    video/flv

    WMV

    video/x-ms-wmv

    AVI

    video/x-msvideo

    M4V

    video/m4v

    F4V

    application/f4v

    MPEG

    video/mpeg

    M3U8

    application/octet-stream

    _3GP/3GP

    video/3gpp

    ASF

    video/x-ms-asf

    MKV

    video/x-matroska

    WEBM

    video/webm

    MPD

    video/dash

    Table 2 Parameters in the request header of an audio file

    File Name Extension

    Content-Type

    MP3

    audio/mp3

    WMA

    audio/wma

    APE

    audio/ape

    FLAC

    audio/flac

    AAC

    audio/aac

    AC3

    audio/ac3

    MMF

    audio/mmf

    AMR

    audio/amr

    M4A

    audio/m4a

    M4R

    audio/m4r

    OGG

    audio/ogg

    WAV

    audio/wav

    WV

    audio/wv

    MP2

    audio/mp2

  5. Call the API for confirming media asset upload.

    POST https://vod.cn-north-4.myhuaweicloud.com/v1.0/{project_id}/asset/status/uploaded
    
    {
    	 "asset_id": "0f4d3f1f32ec353d8866f2d84a036124",
    	 "status":"CREATED"
    }

After a media asset was uploaded, you can view details about the media asset on the VOD console.

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback