Article Directory
- introduction
- 1. Use video on demand to realize the overall process of audio and video upload
- 2. Upload the sdk on the web side
- Summarize
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
-
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.
-
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.
-
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.
-
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.
-
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.
-
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
After the creation is successful, you will get the key Id and Secret
to add permissions for the user
Search for vod
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;
}
accessKeyId
The sum here is the sum of the users accessKeySecret
we created aboveram
id
secret
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 exist
it may be due to the following reasons:
-
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.
-
You may have misspelled the name of the storage location. Make sure the name you provide exactly matches the storage location name in ALICLOUD.
-
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.
-
It may be that the version of the **@alicloud/pop-core library is not compatible**, it is recommended to update to the latest version.
-
Have sufficient permissions to access the storage location. Your account must have permission to access and create this storage location.
code: 'InvalidStorage.NotFound'
message: 'The storageLocation does not exist'
I am the first one here, there is no startup storage location.
啊啊啊啊啊 这里卡了我好久啊,问了阿里云的在线服务,需要启用存储位置才行!!!
After enabling, when calling the interface, it returns successfully
2. The client uploads vod
1. Download the official demo
Find the official example and download the vue source code example.
2. Change the package.json file
npm run dev start demo
npm run dev
3. Change the upload interface address in the demo
Replace uploadAutn.vue
the in createUrl
with your own interface address for obtaining the upload certificate
4. Test upload
View uploaded videos in on-demand management
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.NotFound
method 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.