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

bytes-bank-client

v1.0.27

Published

The Bytes Bank Client SDK is a comprehensive JavaScript library designed to simplify file uploads to your media storage solutions. It provides developers with an easy-to-use interface to manage media uploads with built-in features such as progress trackin

Downloads

1,897

Readme

Bytes Bank Client SDK

Build Status npm version License GitHub Issues

Introduction

The Bytes Bank Client SDK is a comprehensive JavaScript library designed to simplify file uploads to your media storage solutions. It provides developers with an easy-to-use interface to manage media uploads with built-in features such as progress tracking, error handling, and the ability to abort uploads.

Features

  • Easy file uploads
  • Progress tracking
  • Upload success and error handling
  • Ability to abort ongoing uploads
  • Parse Image/Video file to base64

Installation

To install the SDK, run the following command in your terminal:

npm install bytes-bank-client

Usage

Step 1: Import the SDK Client

First, import the SDK into your JavaScript or TypeScript file:

import { BytesBankClient } from "bytes-bank-client";

Step 2: Create an Instance of the SDK

To ensure stability and prevent data loss during re-renders, instantiate the SDK outside the component boundary. You need to provide the collection name, and you can optionally include the clientKey and clientSecret:

const client = new BytesBankClient({
	collection: "your collection name",
	clientKey: "your_client_key", // Optional if set in environment variables
	clientSecret: "your_client_secret", // Optional if set in environment variables
});

Step 3: Upload a File

To upload a file, use the send method. This method requires three parameters:

  1. Your selected file: The actual media file you want to upload.
  2. File identification: A unique identifier for the file, which can be a random number or string.
  3. Upload callback: A callback function that handles various upload events.

The upload callback receives two parameters: action and event.

  1. The action can represent different states of the upload process:

    1. progress: This action occurs while the file is uploading, providing the current upload progress as a percentage.
    2. success: This action occurs when the file has been successfully uploaded, returning the response for the uploaded media.
    3. abort: This action occurs when you abort the upload process, returning the file ID.
    4. error: This action occurs if there is an error during the upload, providing the reason for the failure.
  2. The events contains two properties: fileId and data

    1. file id is basic file identification
    2. data contains the success or error response

Here’s an example of how to implement the upload functionality:

const uploadingCallbacks = (action: string, event: any) => {
	const { fileId, data } = event;
	switch (action) {
		case "progress":
			console.log(`Uploading Progress: ${data}%`);
			break;
		case "success":
			console.log("Upload Success.", event);
			break;
		case "abort":
			console.log("Upload aborted.");
			break;
		case "error":
			console.log("Uploading Error.", event);
			break;
		default:
			break;
	}
};

client.send("your media file", "unique file ID", uploadingCallbacks);

Step 4: Abort an Upload

If you need to abort an ongoing upload, you can use the abort method with the file ID:

client.abort("file id");

Additional Feature: Media Parsing

The Bytes Bank Client SDK includes a media parsing feature that allows you to convert media files (both images and videos) into their base64 representations. This is particularly useful for scenarios where you need to preview media files before uploading them or when you want to embed media directly into HTML or JSON data.

Valid File Types

The mediaParser function only processes files that are either images or videos. If a file type is invalid, its corresponding entry in the parsed media array will have a null base64 value, allowing you to handle it gracefully in your application.

This media parsing capability enhances the functionality of the Bytes Bank Client SDK, making it easier for developers to work with media files before uploading them.

How to Use the Media Parsing Feature

You can utilize the mediaParser function from the SDK to process either a FileList (which represents multiple files selected through an input element) or a single File. The function will return an array of parsed media objects, each containing the original file, a unique identifier, and its base64 representation.

Example Usage

Here's a step-by-step guide on how to use the mediaParser function:

  1. Import the mediaParser Function

    First, ensure you import the mediaParser function from the SDK:

    import { mediaParser } from "bytes-bank-client";
  2. Call the mediaParser function

    The function will return an array of parsed media objects, each containing the original file, a unique identifier, and its base64 representation.

    const files = document.getElementById("fileInput").files; // Assuming a file input element or your uploaded files
    const parsedMedia = await mediaParser(files);
    console.log(parsedMedia);

Conclusion

The Bytes Bank Client SDK is designed to make file uploads simple and efficient. By following these steps, you can easily integrate media upload functionality into your application, as well as leverage the additional media parsing feature. For further details, refer to the LinkedIn