This example provides an example of uploading videos from your server, using NodeJS in TypeScript.
- Install dependencies
npm install
- Copy and edit
.env
file
cp .env.example .env
The sample code will upload a video, and print the video key. You may store this video key in your database, and use them to construct the m3u8 URL for playback.
npm run start
Expected output:
Uploading video from ./resources/drone-view-by-sascha-weber.mp4
Uploaded video key: Us9cIcVMHB9U
We already separate the code that can be copy/paste directly, and the code that required you to edit, so to include them in your project:
- Copy the code in
src/byteark-stream
to your project. - Install some dependencies:
npm install --save axios mime-type tus-js-client @sinclair/typebox
- Using
ByteArkStreamService
class just like the sample code insrc/index.ts
.
const streamService = new ByteArkStreamService({
accessToken: "<BYTEARK_STREAM_ACCESS_TOKEN>",
defaultProjectKey: "<BYTEARK_STREAM_DEFAULT_PROJECT_KEY>",
});
const videoFilePath = "<YOUR_VIDEO_FILE_PATH>";
const videoTitle = "<YOUR_VIDEO_TITLE>";
console.log(`Uploading video from ${videoFilePath}`);
const videoKey = await streamService.createAndUploadVideo({
localFilePath: videoFilePath,
title: videoTitle,
});
console.log(`Uploaded video key: ${videoKey}`);