npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@uploadx/client

v0.0.4

Published

Resumable upload client for browser and Node.js

Readme

UploadX Client

npm version

A JavaScript client for resumable file uploads with chunking support. Works with node-uploadx server implementation.

Features

  • Resumable Uploads: Continue uploads from where they left off after interruptions
  • Chunked Uploads: Split large files into manageable chunks
  • Progress Tracking: Real-time upload progress monitoring
  • Cross-Platform: Works in both browser and Node.js environments
  • Multiple Data Sources: Support for File, Blob, Stream, Buffer, and more
  • Automatic Retries: Built-in retry mechanism with exponential backoff
  • Cancellation: Ability to abort ongoing uploads

Installation

npm install @uploadx/client

Usage

Basic File Upload (Node.js)

import { UploadxClient } from "@uploadx/client";
import fs from "node:fs";

async function uploadFile() {
  // Create a new client instance
  const client = new UploadxClient({
    chunkSize: 8 * 1024 * 1024, // 8MB chunks
  });

  const filePath = "./large-file.mp4";
  const stats = await fs.promises.stat(filePath);

  // Upload the file
  await client.fileUpload(
    "https://your-server.com/upload",
    filePath,
    {
      name: "uploaded-file.mp4",
      mimeType: "video/mp4",
      size: stats.size,
      lastModified: stats.mtimeMs,
    },
    (progress) => {
      console.log(`Upload progress: ${(progress * 100).toFixed(2)}%`);
    }
  );

  console.log("Upload completed successfully!");
}

uploadFile().catch(console.error);

Browser Upload (with File object)

import { UploadxClient } from "@uploadx/client";

async function uploadFile(file) {
  const client = new UploadxClient();

  await client.upload(
    "https://your-server.com/upload",
    file,
    {
      name: file.name,
      mimeType: file.type,
      size: file.size,
      lastModified: file.lastModified,
    },
    (progress) => {
      updateProgressBar(progress);
    }
  );

  alert("Upload completed!");
}

// Example with file input
document.getElementById("fileInput").addEventListener("change", (event) => {
  const file = event.target.files[0];
  if (file) {
    uploadFile(file);
  }
});

Manual Upload Session

You can manually create an upload session and then upload data to it. This is useful when you need more control over the upload process or when implementing custom upload workflows:

import { UploadxClient } from "@uploadx/client";
import fs from "node:fs";

async function manualUploadSession() {
  const client = new UploadxClient();
  const filePath = "./large-file.mp4";

  // Get file stats for metadata
  const stats = await fs.promises.stat(filePath);

  // Define metadata
  const metadata = {
    name: "manual-upload.mp4",
    mimeType: "video/mp4",
    size: stats.size,
    lastModified: stats.mtimeMs,
  };

  try {
    // Create upload session
    const session = await client.createUpload(
      // or createFileUpload
      "https://your-server.com/upload",
      metadata
    );

    console.log(`Upload session created: ${session.url}`);
    console.log(`Already uploaded bytes: ${session.uploadedBytes || 0}`);

    // Now you can use the session URL to resume the upload
    if (session.uploadedBytes !== undefined) {
      console.log(`Resuming upload from byte ${session.uploadedBytes}`);
    }

    await client.resumeFileUpload(
      session.url,
      filePath,
      metadata,
      (progress) => {
        console.log(`Upload progress: ${(progress * 100).toFixed(2)}%`);
      }
    );

    console.log("Upload completed successfully!");
  } catch (error) {
    console.error("Upload session failed:", error);
  }
}

manualUploadSession().catch(console.error);

API Reference

UploadxClient

Constructor

new UploadxClient(config?: UploadConfig)

Parameters:

  • config (optional): Configuration options
    • chunkSize: Size of each chunk in bytes (default: 5MB)
    • retryConfig: Configuration for axios-retry
    • requestConfig: Configuration for axios requests

Methods

fileUpload

Uploads a file from disk (Node.js only).

fileUpload(
  endpoint: string,
  filePath: string,
  metadata: UploadMetadata,
  onProgress?: ProgressCallback,
  signal?: AbortSignal
): Promise<void>
upload

Uploads data from various sources (Blob, File, Stream, Buffer).

upload(
  endpoint: string,
  data: Uploadable,
  metadata: UploadMetadata,
  onProgress?: ProgressCallback,
  signal?: AbortSignal
): Promise<void>
resumeUpload

Resumes an upload from a previously created session.

resumeUpload(
  url: string,
  data: Uploadable,
  metadata: UploadMetadata,
  onProgress?: ProgressCallback,
  signal?: AbortSignal
): Promise<void>
resumeFileUpload

Resumes a file upload from disk (Node.js only).

resumeFileUpload(
  url: string,
  filePath: string,
  metadata: UploadMetadata,
  onProgress?: ProgressCallback,
  signal?: AbortSignal
): Promise<void>
createUpload

Creates a new upload session on the server.

createUpload(
  endpoint: string,
  metadata: UploadMetadata,
  signal?: AbortSignal
): Promise<{ url: string; uploadedBytes?: number }>
updateUpload

Updates metadata for an existing upload.

updateUpload(
  url: string,
  metadata: Partial<UploadMetadata>,
  signal?: AbortSignal
): Promise<void>
getUploadStatus

Gets the current upload progress from the server.

getUploadStatus(
  url: string,
  metadata?: Partial<UploadMetadata>,
  signal?: AbortSignal
): Promise<{ uploadedBytes: number }>
deleteUpload

Deletes an existing upload from the server.

deleteUpload(url: string, signal?: AbortSignal): Promise<void>
abort

Aborts all ongoing upload operations.

abort(): void

Types

UploadMetadata

interface UploadMetadata {
  name: string;
  mimeType?: string;
  size: number;
  lastModified?: number;
  [key: string]: unknown;
}

ProgressCallback

type ProgressCallback = (progress: number) => void;

Examples

The repository includes example code to help you get started:

Upload Client Example

examples/client.ts demonstrates how to upload a file with progress tracking:

ts-node examples/client.ts /path/to/file.mp4

Browser Example

The repository includes a browser demo (examples/browser/index.html) that shows how to implement resumable uploads in web applications with progress tracking, session management, and upload controls (upload, abort, resume, delete).

Server Requirements

This client is specifically designed to work with the node-uploadx server implementation, which provides the necessary protocol support for resumable uploads.

License

MIT