语音通话 VOICECALL-Node.js:“获取录音文件下载地址API”代码样例

时间:2024-09-25 15:29:01

“获取录音文件下载地址API”代码样例

/*jshint esversion: 6 */
var https = require('https');
var util = require('./reqUtil.js');
var querystring = require('querystring');
/**
 * Get the download link of record file.
 * @param fileName  record file name
 * @param recordDomain  domain name of record file restore server
 * @returns
 */
function getRecordLinkAPI(fileName, recordDomain, xaksk) {
    if(fileName === undefined || fileName === null || recordDomain === undefined || recordDomain === null){
        return;
    }
    if(xaksk === undefined || xaksk === null){
        return;
    }

    var location;

    var method = 'GET';
    var uri = '/rest/provision/voice/record/v1.0';
    var queryParams = querystring.stringify({'fileName': fileName, 'recordDomain': recordDomain});

    var options = util.createOptions(method, uri, queryParams, xaksk);

    var req = https.request(options, function (res) {
        if(301 === res.statusCode){
            location = Object.getOwnPropertyDescriptor(res.headers, 'location').value;
        }
        var resHeaders = JSON.stringify(res.headers);
        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            console.log('resp:', chunk); //打印响应数据
        });
    });

    req.on('error', function(e) {
        console.error('problem with request: ' + e); //打印错误信息
    });
    req.end(); //结束请求
    return location;
}
module.exports = {
        getRecordLinkAPI
};
support.huaweicloud.com/devg-VoiceCall/rtc_04_0017.html