0

我正在制作 amazon chime sdk 录音演示,即https://github.com/aws-samples/amazon-chime-sdk-recording-demo录音已正确保存S3 Bucket,现在我想将录制的文件保存在我的服务器上,我相信,我需要更改此文件https://github.com/aws-samples/amazon-chime-sdk-recording-demo/blob/master/recording/record.js 代码以调用S3 Bucket方法来保存录音文件

const timestamp = new Date();
const fileTimestamp = timestamp.toISOString().substring(0,19);
const year = timestamp.getFullYear();
const month = timestamp.getMonth() + 1;
const day = timestamp.getDate();
const hour = timestamp.getUTCHours();
const fileName = `${year}/${month}/${day}/${hour}/${fileTimestamp}.mp4`;
new S3Uploader(BUCKET_NAME, fileName).uploadStream(transcodeStreamToOutput.stdout);

并且S3 Bucket Class code

/**
 * S3Upload Class
 * Upload a recording artifact to S3
 */
class S3Uploader {
    /**
     * @constructor
     * @param {*} bucket - the S3 bucket name uploaded to
     * @param {*} key - the file name in S3 bucket
     */
    constructor(bucket, key) {
        this.bucket = bucket;
        this.key = key;
        this.s3Uploader = new AWS.S3({ params: { Bucket: bucket, Key: key } });
        console.log(`[upload process] constructed a S3 object with bucket: ${this.bucket}, key: ${this.key}`);
    }

    uploadStream(stream) {
        const managedUpload = this.s3Uploader.upload({ Body: stream }, (err, data) => {
            if (err) {
                console.log('[stream upload process] - failure - error handling on failure', err);
            } else {
                console.log(`[stream upload process] - success - uploaded the file to: ${data.Location}`);
                process.exit();
            }
        });
        managedUpload.on('httpUploadProgress', function (event) {
            console.log(`[stream upload process]: on httpUploadProgress ${event.loaded} bytes`);
        });
    }
}

现在我想更改此代码S3Uploader以将流上传到我的服务器。有没有人这样做过,我真的很感激。谢谢

4

0 回答 0