The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.

Access Process

Last updated: 2024-12-20 10:17:38

There are two ways to access document transcoding:
Registration Callback Method (Recommended for scenarios where callbacks have already been Registered in the Interactive Whiteboard Console, as it allows you to receive transcoding progress and results more promptly)
Active Polling Method (Suitable for scenarios where callbacks are not registered in the Interactive Whiteboard Console)
This document mainly introduces the basic process of initiating document transcoding using the registration callback method.

Preparations

Bucket Configuration (The resources of CFS after document transcoding rely on COS. Before using the document transcoding feature, please first perform Bucket Configuration).
Note
If the bucket is not configured, the transcoded CFS will be stored in the public bucket of the Interactive Whiteboard, with a storage validity period of 7 days. After 7 days, the transcoded files in the public bucket will be automatically deleted, and the URL file will become invalid. It is recommended to perform Bucket Configuration to store the transcoded CFS in your own bucket.
Register Transcoding Callback (To allow the transcoding server to push transcoding results to you in real-time, you need to register a callback URL. For specific methods, please refer to Console Callback Settings).
Note
Due to the time required for transcoding and queuing, it is recommended to use the server-side API to transcode in advance and the client to directly use the transcoding result. It is not recommended to directly call the Interactive Whiteboard SDK's transcoding interface applyFileTranscode on the client to avoid long waits and impact the product experience.
Interaction Process (Registration Callback Method)

交互流程



1. Upload Document (for example, to Tencent Cloud COS)

To enable the Tencent Cloud transcoding server to obtain your courseware for transcoding, you need to provide a URL that the transcoding server can use to download the courseware.
Note:
1. It is recommended to use Tencent Cloud's COS service to provide download addresses. Of course, you can also upload to other storage servers or use other upload methods.
2. Here, the example uses Tencent Cloud COS with the Go language. For more language implementations, please refer to Tencent Cloud COS.
Sample code:
package main

import (
"context"
"fmt"
"log"
"net/http"
"net/url"
"github.com/tencentyun/cos-go-sdk-v5"
"os"
)

func main() {
// Initialize COS resources TODO: Replace `examplebucket-1250000000` and `COS_REGION` with the actual information
domain := "https://examplebucket-1250000000.cos.COS_REGION.myqcloud.com"
u, _ := url.Parse(domain)
b := &cos.BaseURL{BucketURL: u}
cosClient := cos.NewClient(b, &http.Client{
Transport: &cos.AuthorizationTransport{
// TODO: COS_SECRETID needs to be replaced with the user's real SECRETID, COS_SECRETKEY needs to be replaced with the user's real SECRETKEY
SecretID: "COS_SECRETID",
SecretKey: "COS_SECRETKEY",
},
})
// TODO: Object key name to upload to COS
keyName := "test/objectPut.go"
// Local file path
localFilePath := "test/objectPut.go"
// Get file size
file_info, err := os.Stat(localFilePath)
if err != nil {
panic(err)
}

opt := &cos.ObjectPutOptions{}
opt.ObjectPutHeaderOptions = &cos.ObjectPutHeaderOptions{}
opt.ObjectPutHeaderOptions.ContentLength = int(file_info.Size())

// The object key is the unique identifier of the object in the bucket.
// For example, in the access domain name `examplebucket-1250000000.cos.COS_REGION.myqcloud.com/test/objectPut.go`, the object key is `test/objectPut.go`
// Start the upload
_, err = cosClient.Object.PutFromFile(context.Background(), keyName, localFilePath, nil)
if err != nil {
// Upload failed
panic(err)
}
// Upload successful, assemble resultUrl
resultUrl := fmt.Sprintf("%s/%s", domain, keyName)
log.Printf("upload successful! resultUrl[]%s", resultUrl)
}

2. Initiate transcoding

Since dynamic transcoding involves transcoding time and queuing time, it is recommended to use the server API to transcode in advance, and the client directly uses the transcoding result. It is not recommended to directly call the transcoding interface on the client side applyFileTranscode to avoid long waits and impact on product experience.
Note:
1. For interface instructions, please refer to File Transcoding Related Interfaces. For callback events, please refer to File Transcoding Callback Events.
2. Get your SecretId and SecretKey from API Key Management.
3. For sample code of other programming languages or transcoding APIs, please refer to Sample Code Generator.
Sample Code (Golang example):
package main

import (
"fmt"

"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
tiw "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tiw/v20190919"
)

func main() {
// "SECRETID" and "SECRETKEY" need to be obtained from the API Key Management in the console
credential := common.NewCredential(
"SECRETID",
"SECRETKEY",
)
cpf := profile.NewClientProfile()
cpf.HttpProfile.Endpoint = "tiw.tencentcloudapi.com"
client, _ := tiw.NewClient(credential, "ap-guangzhou", cpf)

request := tiw.NewCreateTranscodeRequest()
// SdkAppId is the user's own interactive whiteboard application ID. Url is the download address obtained after uploading the document
params := "{\"SdkAppId\":xxxxxxxxx,\"Url\":\"https://board-sdk-1259648581.file.myqcloud.com/TIC/1590997573551/WelcomeNewStudents.pptx\"}"
err := request.FromJsonString(params)
if err != nil {
panic(err)
}
response, err := client.CreateTranscode(request)
if _, ok := err.(*errors.TencentCloudSDKError); ok {
fmt.Printf("An API error has returned: %s", err)
return
}
if err != nil {
panic(err)
}
fmt.Printf("%s", response.ToJsonString())
}

3. Handle Transcoding Callback

You must ensure that the callback is successfully registered in the console or via API, and the callback URL is publicly accessible to receive transcoding data callbacks properly. If you have not configured the callback yet, please refer to Console Callback Settings.
Sample Code (Golang example):
import (
"encoding/json"
"log"
"testing"
)

const (
// Transcoding progress change
TranscodeProgressChanged = "TranscodeProgressChanged"
// Transcoding completion
TranscodeFinished = "TranscodeFinished"
)

// Transcoding error
type commonError struct {
Code string `json:"Code"`
Message string `json:"Message"`
}

// Transcoding event data
type EventData struct {
Error *commonError `json:"Error"` // Error information; if empty, there is no error
TaskId string `json:"TaskId"` // Document transcoding task id
Progress int `json:"Progress"` // Task progress
Resolution string `json:"Resolution"` // Document resolution
Title string `json:"Title"` // Document title
Pages int `json:"Pages"` // Total pages of the document
ResultUrl string `json:"ResultUrl"` // Document transcoding result
ThumbnailUrl string `json:"ThumbnailUrl"` // Thumbnail Url
ThumbnailResolution string `json:"ThumbnailResolution"` // Thumbnail Resolution
CompressFileUrl string `json:"CompressFileUrl"` // Compressed file download Url for transcoding result
}

// Transcoding callback result
type TranscodeResult struct {
EventType string `json:"EventType"` // Event type
ExpireTime int `json:"ExpireTime"` // Signature expiration time
SdkAppId int `json:"SdkAppId"` // Interactive Whiteboard Application SdkAppId
Sign string `json:"Sign"` // Callback signature
Timestamp int `json:"Timestamp"` // Unix timestamp when the event was generated, in seconds
EventData EventData `json:"EventData"` // Event specific information
}

// Transcoding event callback interface registered in Tencent Document Transcoding backend via console or API
func TrascoderEventCallback(resultStr []byte) {
transcodeResult := TranscodeResult{}

err := json.Unmarshal(resultStr, &transcodeResult)
if nil != err {
panic(err)
}
// Handle transcoding results
if TranscodeProgressChanged == transcodeResult.EventType {
// Transcoding progress change
log.Printf("transcode progress [%d]", transcodeResult.EventData.Progress)
} else if TranscodeFinished == transcodeResult.EventType {
// Transcoding completion
if nil != transcodeResult.EventData.Error {
// Transcoding failure
log.Printf("transcode failed!err[%v]", transcodeResult.EventData.Error)
return
}
// Transcoding success
log.Printf("transcode successful! EventData[%v]", transcodeResult.EventData)
}
}

4. Use the transcoding results

The client sets the transcoding results into the interactive whiteboard, to achieve document previous/next, previous/next page, and other features. Refer to whiteboard interface description for whiteboard interface.
Code example (JS example)
// The client assembles parameters based on the document transcoding returned results
let config = {
url: eventData.resultUrl,
title: eventData.title,
pages: eventData.pages,
resolution: eventData.resolution
}
// Add the document transcoding results to the whiteboard
this.teduBoard.addTranscodeFile(config);
Display effect: