🚧 The Shelby Explorer is currently in beta and is under active development

Shelby SymbolMedia Kit

Upload a Video

Upload video to Shelby storage


Introduction

Upload your prepared video to Shelby's decentralized storage network. Once uploaded, your media is distributed across nodes worldwide, ensuring low-latency playback from anywhere.

Workflow diagram showing Install SDK, Initialize, Load Files, and Upload steps
Install SDK
Initialize
Load Files
Upload

Prerequisites

Before uploading, make sure you have:

  • API keys configured
  • Media files ready (MP4, HLS, or DASH)

For streaming video, we recommend preparing your media into HLS format using @shelby-protocol/media-prepare. This example uses HLS output.

Step 1: Install the SDK

Install the Shelby SDK for Node.js:

npm install @shelby-protocol/sdk @aptos-labs/ts-sdk

Step 2: Initialize the Client

Create a Shelby client with your API key:

import { ShelbyNodeClient } from "@shelby-protocol/sdk/node";
import { Network } from "@aptos-labs/ts-sdk";

const client = new ShelbyNodeClient({
  network: Network.SHELBYNET,
  apiKey: process.env.SHELBY_API_KEY,
});

Step 3: Load Your Media Files

Read your prepared HLS files. You'll have a manifest file and segment files:

import fs from "fs";

// Read your HLS output files
const playlist = fs.readFileSync("./output/playlist.m3u8");
const segment001 = fs.readFileSync("./output/segment-001.ts");
const segment002 = fs.readFileSync("./output/segment-002.ts");
const segment003 = fs.readFileSync("./output/segment-003.ts");

Step 4: Upload to Shelby

Use batchUpload to upload all files in a single efficient operation. Files are distributed across the decentralized network.

Local Filesplaylist.m3u8segment-001.tssegment-002.tssegment-003.tsShelby NetworkDecentralized Storage
// Set expiration (1 day from now)
const oneDayFromNow = Date.now() * 1000 + 86400_000_000;

// Upload all files in one batch
await client.batchUpload({
  blobs: [
    { blobData: new Uint8Array(playlist), blobName: "video/playlist.m3u8" },
    { blobData: new Uint8Array(segment001), blobName: "video/segment-001.ts" },
    { blobData: new Uint8Array(segment002), blobName: "video/segment-002.ts" },
    { blobData: new Uint8Array(segment003), blobName: "video/segment-003.ts" },
  ],
  expirationMicros: oneDayFromNow,
});

batchUpload is more efficient than uploading files individually. It handles commitment generation, blockchain registration, and storage upload in a single operation.

Blob storage requires payment in ShelbyUSD. Costs scale with file size and storage duration. See Blob Pricing for details.

Understanding Blob Keys

After upload, each file is accessible via a blob key that combines your account address and the file name you specified.

@7b1ada...3996/video/playlist.m3u8Storage AccountYour unique identifierBlob NameFile path you specify

Store the account address and blob name in your database to construct the playback URL later.

Constructing the Playback URL

To play your uploaded video, construct a URL using the Shelby storage API:

// Your storage account address and blob name
const account = "7b1ada...3996";
const blobName = "video/playlist.m3u8";

// Construct the playback URL
const playbackUrl = `https://api.shelbynet.shelby.xyz/v1/blobs/${account}/${blobName}`;

// Use this URL with VideoPlayer
<VideoPlayer src={playbackUrl} />

The URL format is:

https://api.shelbynet.shelby.xyz/v1/blobs/{account}/{blobName}

Next Steps


On this page