Video upload from client refers to uploading local videos to the VOD platform by an end user of the application. For more information, please see Guide. This document describes how to generate a signature for upload from client.
The overall process for upload from client is as follows:
To support upload from client, you need to build two backend services: signature distribution service and event notification receipt service.
At this point, the entire video upload and processing flow ends.
For more information on the signature for upload from client, please see Signature for Upload from Client.
/**
* Calculate a signature
*/
function createFileUploadSignature({ timeStamp = 86400, procedure = '', classId = 0, oneTimeValid = 0, sourceContext = '' }) {
// Determine the generation time and expiration time of the signature
let current = parseInt((new Date()).getTime() / 1000)
let expired = current + timeStamp; // Signature validity period: 1 day
// Enter the parameters into the parameter list
let arg_list = {
//required
secretId: this.conf.SecretId,
currentTimeStamp: current,
expireTime: expired,
random: Math.round(Math.random() * Math.pow(2, 32)),
//opts
procedure,
classId,
oneTimeValid,
sourceContext
}
// Calculate the signature
let orignal = querystring.stringify(arg_list);
let orignal_buffer = new Buffer(orignal, "utf8");
let hmac = crypto.createHmac("sha1", this.conf.SecretKey);
let hmac_buffer = hmac.update(orignal_buffer).digest();
let signature = Buffer.concat([hmac_buffer, orignal_buffer]).toString("base64");
return signature;
}
/**
* Respond to a signature request
*/
function getUploadSignature(req, res) {
res.json({
code: 0,
message: 'ok',
data: {
signature: gVodHelper.createFileUploadSignature({})
}
});
}
Upload a .mp4 file to Tencent Video Cloud and get the online watch URL. Tencent Video Cloud can meet various video watch needs such as nearby scheduling, instant live streaming and playback, dynamic acceleration, and global connection, delivering a smooth watch experience.
TXUGCRecord
API to shoot a short video, and a .mp4 short video file will be generated after the shoot ends and be called back.TXUGCPublish
API to publish the video. After the video is successfully published, the SDK will call back the watch URL to you.SecretID
or SecretKey
for upload signature calculation into the client code of the application, as their disclosure will cause security risks. If attackers get such information by cracking the application, they can misappropriate your traffic and storage service.SecretID
and SecretKey
on your server and send the signature to the application. As the server is generally hard to be intruded, the security is guaranteed.Signature
field is correctly passed in; otherwise, the release will fail.You can upload the shot or edited video as described in previous documents or upload a local video on your phone.
Use the TXVideoEditer.generateVideo(int videoCompressed, String videoOutputPath)
API to compress the selected video. Four resolutions are supported for compression currently, and compression with customizable bitrate will be supported in the future.
Publish the generated .mp4 file to Tencent Cloud. The application needs to get the upload signature with a short validity period for file upload as instructed in Signature Distribution.TXUGCPublish
(in TXUGCPublish.h
) is used to publish .mp4 files to VOD so as to meet various video watch needs such as nearby scheduling, instant live streaming and playback, dynamic acceleration, and global connection.
TXPublishParam * param = [[TXPublishParam alloc] init];
param.signature = _signature; // Enter the upload signature calculated in step 4
// Video file path generated by shoot, which can be obtained through the `onRecordComplete` callback of `TXVideoRecordListener`
param.videoPath = _videoPath;
// Path of the first-frame video preview image generated by shoot. The value is the file path specified by calling `startRecord`. You can also specify a path and save the `UIImage` obtained in the `onRecordComplete` callback of `TXVideoRecordListener` to the specified path. It can be set to `nil`.
param.coverPath = _coverPath;
TXUGCPublish *_ugcPublish = [[TXUGCPublish alloc] init];
// Checkpoint restart is used for file release by default
_ugcPublish.delegate = self; // Set the `TXVideoPublishListener` callback
[_ugcPublish publishVideo:param];
The release process and result will be returned through the TXVideoPublishListener
API (defined in the TXUGCPublishListener.h
header file):
onPublishProgress
is used to return the file release progress, the uploadBytes
parameter indicates the number of uploaded bytes, and the totalBytes
parameter indicates the total number of bytes that need to be uploaded.@optional
-(void) onPublishProgress:(NSInteger)uploadBytes totalBytes: (NSInteger)totalBytes;
onPublishComplete
is used to return the release result, the errCode
and descMsg
fields of TXPublishResult
indicate the error code and error message respectively, videoURL
indicates the VOD address of the short video, coverURL
indicates the cloud storage address of the video cover, and videoId
indicates the cloud storage ID the video file, with which you can call VOD's server APIs.@optional
-(void) onPublishComplete:(TXPublishResult*)result;
After the video is successfully uploaded in step 3, the video fileId
, playback URL, and cover URL will be returned. You can directly pass in the fileId
or playback URL to the VOD player for playback.
Was this page helpful?