@alicloud/pop-core in node obtains Aliyun video-on-demand vod upload address and certificate, uploads sdk on the web side, and solves the problem of `InvalidStorage.NotFound` error when obtaining upload certificate

introduction

In web development, video upload function is a very common requirement. Using Alibaba Cloud VOD service as a storage service can improve the efficiency and stability of video uploads, and also provides a series of tools and APIs for developers to use. This article will introduce how to use @alicloud/pop-core to obtain the Aliyun video-on-demand vod upload address and certificate as the web upload SDK, and will also provide a method to solve the problem of obtaining the upload certificate error InvalidStorage.NotFound. Through the study of this article, readers can quickly add video upload function to their projects and solve common errors.

1. Use video on demand to realize the overall process of audio and video upload

The overall process of using VOD to realize audio and video upload, storage, processing and playback is as follows
insert image description here

  1. Audio and video upload: First, users need to upload their own audio or video to Alibaba Cloud VOD. This process can be carried out by using VOD console, uploading SDK, API operation, etc. Alibaba Cloud VOD supports the upload of multiple media formats, and integrates the uploaded audio or video.

  2. Media processing: After uploading, VOD will automatically process audio and video files. This process includes transcoding, packaging, resolution adaptation, etc., to produce video and audio that can be played on various devices. In addition, users can also configure additional processing such as watermarks, screenshots, and purification.

  3. Media material management: After the processing is completed, VOD will generate a unique VideoID for each audio or video, and store related metadata information. Users can use API or SDK to query and modify such information.

  4. Storage and distribution: VOD provides users with audio and video storage services, which can realize audio and video storage and backup. In addition, through the Alibaba Cloud global CDN network, VOD can also realize the rapid distribution of audio and video.

  5. Play: Alibaba Cloud VOD provides multiple ways for users to play audio and video, including playing on the client through the player SDK, playing on the web page through the Web player, or playing on the third-party player through the URL.

  6. Analysis and optimization: In addition, Alibaba Cloud VOD also provides a wealth of audio and video analysis functions to help users understand audio and video playback and user behavior, and optimize audio and video release strategies accordingly.

2. Upload the sdk on the web side

1. Open the video on demand service

For the specific process, you can read this article to purchase and activate the video-on-demand service.

2. Create ram user

insert image description here
insert image description here
After the creation is successful, you will get the key Id and Secret
insert image description here
to add permissions for the user
insert image description here
Search for vod
insert image description here
insert image description here

3. Obtain the upload address and credentials

1. The express framework in node uses @alicloud/pop-core to obtain upload credentials

Here we take node as an example. For
other methods, please refer to the official website: https://help.aliyun.com/zh/vod/developer-reference/obtain-upload-urls-and-credentials?spm=a2c4g.11186623.0.0.d5851ee8drr4nV#task -1997361

1. Install the Node.js SDK

npm install @alicloud/pop-core --save

2. Initialize the Node.js SDK

AccessKey initialization
Fill in the AccessKey information to initialize. Examples are as follows:

var RPCClient = require('@alicloud/pop-core').RPCClient;

function initVodClient(accessKeyId, accessKeySecret,) {
    
    
    var regionId = 'cn-shanghai';   // 点播服务接入地域
    var client = new RPCClient({
    
    //填入AccessKey信息
        accessKeyId: accessKeyId,
        accessKeySecret: accessKeySecret,
        endpoint: 'http://vod.' + regionId + '.aliyuncs.com',
        apiVersion: '2017-03-21'
    });

    return client;
}

accessKeyIdThe sum here is the sum of the users accessKeySecretwe created aboveramidsecret

3. Obtain the upload address and credentials

function getvod = async (req, res) => {
    
    
  // 请求示例
  let client = initVodClient( // 这里就是传入创建rma账号的id和secret
    'accessKeyId',
    'accessKeySecret'
  );

  const vodback = await client.request("CreateUploadVideo", {
    
    
    Title: 'test vod',
    FileName: 'filename.mp4'
  }, {
    
    })
  res.status(200).json({
    
    vod:vodback})
}

Then we can write an interface test

router.get('/getvod', getvod)

Then use postman to call the interface. If an error is reported, The storageLocation does not existit may be due to the following reasons:

  1. You may not have created this storage location in your ALICLOUD account . You need to go to your ALICLOUD management console to create this location.

  2. You may have misspelled the name of the storage location. Make sure the name you provide exactly matches the storage location name in ALICLOUD.

  3. If you have hardcoded the name of the storage location in your code, it may be due to capitalization errors or extra spaces. Check your code again.

  4. It may be that the version of the **@alicloud/pop-core library is not compatible**, it is recommended to update to the latest version.

  5. Have sufficient permissions to access the storage location. Your account must have permission to access and create this storage location.
    insert image description here

code: 'InvalidStorage.NotFound'
message: 'The storageLocation does not exist'

I am the first one here, there is no startup storage location.

啊啊啊啊啊 这里卡了我好久啊,问了阿里云的在线服务,需要启用存储位置才行!!!

insert image description here

insert image description here
After enabling, when calling the interface, it returns successfully
insert image description here

2. The client uploads vod

1. Download the official demo

Find the official example and download the vue source code example.
insert image description here

2. Change the package.json file

insert image description here
npm run dev start demo

npm run dev

3. Change the upload interface address in the demo

Replace uploadAutn.vuethe in createUrlwith your own interface address for obtaining the upload certificate
insert image description here

4. Test upload

insert image description here
View uploaded videos in on-demand management
insert image description here

Summarize

In this article, we introduce how to use @alicloud/pop-core to obtain the upload address and credentials of Aliyun video on demand vod, and provide a InvalidStorage.NotFoundmethod to solve the problem of error reporting. Through the study of this article, readers can easily add the video upload function to their own projects, and can quickly solve problems when they encounter problems. Alibaba Cloud VOD service is a very reliable and efficient video storage and processing service. It not only supports video upload and storage, but also provides various video processing and distribution functions. In future work, Alibaba Cloud VOD service will be a very useful tool, and we hope to help readers better understand and use it through this article.

Guess you like

Origin blog.csdn.net/jieyucx/article/details/132097938