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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fastpix/uploader

v1.0.3

Published

A robust SDK for chunked file uploads.

Downloads

1

Readme

Uploads SDK

This SDK helps you efficiently upload large files from the browser by splitting them into chunks and also gives you the ability to pause and resume your uploads. While the SDK itself is written in TypeScript, we are publishing only the JavaScript output as npm package. Types support for TypeScript users will be released in a later version.

Please note that this SDK is designed to work only with FastPix and is not a general purpose uploads SDK.

Features:

  • Chunking: Files are automatically split into chunks (configurable, default size is 16MB/chunk).
  • Pause and Resume: Allows temporarily pausing the upload and resuming after a while.
  • Retry: Uploads might fail due to temporary network failures. Individual chunks are retried for 5 times with exponential backoff to recover automatically from such failures.
  • Lifecycle Event Listeners: Listen to various upload lifecycle events to provide real-time feedback to users.
  • Error Handling and Reporting: Comprehensive error handling to manage upload failures gracefully and inform users of issues.
  • Customizability: Developers can customize the chunk size and retry attempts based on their specific needs and network conditions.

Installation

To install the SDK, you can use npm or your favourite node package manager 😉:

npm i @fastpix/uploader

Basic Usage

To get started with SDK, you will need a signed URL.

To make API requests, you'll need a valid Access Token and Secret Key. See the Basic Authentication Guide for details on retrieving these credentials.

Once you have your credentials, use the Upload media from device API to generate a signed URL for uploading media.

Import

import {Uploader} from "@fastpix/uploader"

Integration

const fileUploader = Uploader.init({
    endpoint: 'https://example.com/signed-url', // Replace with the signed URL.
    file: mediaFile, // Provide the media file you want to upload.
    chunkSize: 5120, // Specify the chunk size in kilobytes (KB). Minimum allowed chunk size is 5120KB (5MB).

    // Additional optional parameters can be specified here as needed
})

Monitor the upload progress through lifecycle events


// Track upload progress
fileUploader.on('progress', event => { 
    console.log("Upload Progress:", event.detail); 
}); 

// Handle errors during the upload process
fileUploader.on('error', event => { 
    console.error("Upload Error:", event.detail.message); 
}); 

// Trigger actions when the upload completes successfully
fileUploader.on('success', event => { 
    console.log("Upload Completed"); 
}); 

// Track the initiation of each chunk upload
fileUploader.on('attempt', event => { 
    console.log("Chunk Upload Attempt:", event.detail); 
}); 

// Track failures of each chunk upload attempt
fileUploader.on('chunkAttemptFailure', event => { 
    console.log("Chunk Attempt Failure:", event.detail); 
}); 

// Perform an action when a chunk is successfully uploaded
fileUploader.on('chunkSuccess', event => { 
    console.log("Chunk Successfully Uploaded:", event.detail); 
}); 

// Triggers when the connection is back online
fileUploader.on('online', event => { 
    console.log("Connection Online"); 
}); 

// Triggers when the connection goes offline
fileUploader.on('offline', event => { 
    console.log("Connection Offline"); 
});

Managing Uploads

You can control the upload lifecycle with the following methods:

  • Pause an Upload:

    fileUploader.pause(); // Pauses the current upload
  • Resume an Upload:

    fileUploader.resume(); // Resume the current upload
  • Abort an Upload:

    fileUploader.abort(); // Abort the current upload

Parameters Accepted

This SDK supports the following parameters:

  • endpoint (required):

    The URL endpoint where the file will be uploaded.

  • file (required):

    The file object that you want to upload.

  • chunkSize (optional):

    Size of each chunk in kilobytes (KB). Default is 16 MB (16384 KB), with a minimum of 5 MB (5120 KB) and a maximum of 500 MB (512000 KB).

  • maxFileSize (optional):

    The maximum file size allowed for upload, specified in kilobytes (KB). This helps prevent excessively large uploads.

  • retryChunkAttempt (optional):

    Number of retries per chunk in case of failure. Default is 5 retries.

  • delayRetry (optional):

    Delay between retry attempts (in milliseconds) after a chunk upload fails. Default is 1000 ms.