Skip to content

byteark/byteark-stream-resumable-upload-nodejs-example

Repository files navigation

ByteArk Stream Resumable Upload with NodeJS

This example provides an example of uploading videos from your server, using NodeJS in TypeScript.

Installation

  1. Install dependencies
npm install
  1. Copy and edit .env file
cp .env.example .env

Running the sample code

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

Using this in your project

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:

  1. Copy the code in src/byteark-stream to your project.
  2. Install some dependencies:
npm install --save axios mime-type tus-js-client @sinclair/typebox
  1. Using ByteArkStreamService class just like the sample code in src/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}`);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published