All Projects → muxinc → Upchunk

muxinc / Upchunk

Uploads Chunks! Takes big files, splits them up, then uploads each one with care (and PUT requests).

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Upchunk

Sbjson
This framework implements a strict JSON parser and generator in Objective-C.
Stars: ✭ 3,776 (+3241.59%)
Mutual labels:  chunk
Google Books Android Viewer
Android library to bridge between RecyclerView and sources like web page or database. Includes demonstrator (Google Books viewer)
Stars: ✭ 37 (-67.26%)
Mutual labels:  chunk
Evennia
Python MUD/MUX/MUSH/MU* development system
Stars: ✭ 1,309 (+1058.41%)
Mutual labels:  mux
Bootstrap Fileinput
An enhanced HTML 5 file input for Bootstrap 5.x/4.x./3.x with file preview, multiple selection, and more features.
Stars: ✭ 5,097 (+4410.62%)
Mutual labels:  chunk
Webpack Hashed Chunkids
a plugin to help webpack to generate unique chunk id based on unique module id
Stars: ✭ 15 (-86.73%)
Mutual labels:  chunk
Go Ts Segmenter
Live TS segmenter and HLS manifest creation in Go
Stars: ✭ 42 (-62.83%)
Mutual labels:  chunk
Laravel Chunk Upload
The basic implementation for chunk upload with multiple providers support like jQuery-file-upload, pupload, DropZone and resumable.js
Stars: ✭ 275 (+143.36%)
Mutual labels:  chunk
Bouncer
Bouncer is a network TCP port redirector/forward proxy (like rinetd) with extra features like Reverse tunneling (like ssh -R), SSL tunneling (like stunnel), connection Failover, LoadBalancing and Clustering. In pure Java (BIO)
Stars: ✭ 103 (-8.85%)
Mutual labels:  mux
Futures Batch
An adapter for futures, which chunks up elements and flushes them after a timeout, or when the buffer is full. (Formerly known as tokio-batch.)
Stars: ✭ 37 (-67.26%)
Mutual labels:  chunk
Bone
Lightning Fast HTTP Multiplexer
Stars: ✭ 1,270 (+1023.89%)
Mutual labels:  mux
Yedda
YEDDA: A Lightweight Collaborative Text Span Annotation Tool. Code for ACL 2018 Best Demo Paper Nomination.
Stars: ✭ 704 (+523.01%)
Mutual labels:  chunk
Librg
🚀 Making multi-player gamedev simpler since 2017
Stars: ✭ 813 (+619.47%)
Mutual labels:  chunk
Hls Trimming Frame Accuracy
JS Code that given a group of HLS chunks, a start timestamp, and end timestamp it creates one MP4 that contains the original V/A frame accuracy trimmed and perfectly aligned
Stars: ✭ 46 (-59.29%)
Mutual labels:  chunk
Mux
A high performance and powerful trie based url path router for Go.
Stars: ✭ 487 (+330.97%)
Mutual labels:  mux
Base64 Async
Non-blocking chunked Base64 encoding
Stars: ✭ 98 (-13.27%)
Mutual labels:  chunk
React Dynamic Route Loading Es6
Auto chunking and dynamic loading of routes with React Router and Webpack 2
Stars: ✭ 297 (+162.83%)
Mutual labels:  chunk
Mux Elixir
Official Mux API wrapper for Elixir projects, supporting both Mux Data and Mux Video.
Stars: ✭ 41 (-63.72%)
Mutual labels:  mux
Go Web Framework Benchmark
⚡ Go web framework benchmark
Stars: ✭ 1,601 (+1316.81%)
Mutual labels:  mux
Violetear
Go HTTP router
Stars: ✭ 100 (-11.5%)
Mutual labels:  mux
Inline Chunk Manifest Html Webpack Plugin
Extension plugin for html-webpack-plugin to inline webpack's chunk manifest. Default inlines in head tag.
Stars: ✭ 83 (-26.55%)
Mutual labels:  chunk

UpChunk

UpChunk Build Status

UpChunk uploads chunks of files! It's a JavaScript module for handling large file uploads via chunking and making a put request for each chunk with the correct range request headers. Uploads can be paused and resumed, they're fault tolerant, and it should work just about anywhere.

UpChunk is designed to be used with Mux direct uploads, but should work with any server that supports resumable uploads in the same manner. This library will:

  • Split a file into chunks (in multiples of 256KB).
  • Make a PUT request for each chunk, specifying the correct Content-Length and Content-Range headers for each one.
  • Retry a chunk upload on failures.
  • Allow for pausing and resuming an upload.

Installation

NPM

npm install --save @mux/upchunk

Yarn

yarn add @mux/upchunk

Script Tags

<script src="https://unpkg.com/@mux/[email protected]"></script>

Basic Usage

Getting an upload URL from Mux.

You'll need to have a route in your application that returns an upload URL from Mux. If you're using the Mux Node SDK, you might do something that looks like this.

const { Video } = new Mux();

module.exports = async (req, res) => {
  // This ultimately just makes a POST request to https://api.mux.com/video/v1/uploads with the supplied options.
  const upload = await Video.Uploads.create({
    cors_origin: 'https://your-app.com',
    new_asset_settings: {
      playback_policy: 'public',
    },
  });

  // Save the Upload ID in your own DB somewhere, then
  // return the upload URL to the end-user.
  res.end(upload.url);
};

Then, in the browser

import * as UpChunk from '@mux/upchunk';

// Pretend you have an HTML page with an input like: <input id="picker" type="file" />
const picker = document.getElementById('picker');

picker.onchange = () => {
  const getUploadUrl = () =>
    fetch('/the-endpoint-above').then(res =>
      res.ok ? res.text() : throw new Error('Error getting an upload URL :(')
    );

  const upload = UpChunk.createUpload({
    endpoint: getUploadUrl,
    file: picker.files[0],
    chunkSize: 5120, // Uploads the file in ~5mb chunks
  });

  // subscribe to events
  upload.on('error', err => {
    console.error('💥 🙀', err.detail);
  });

  upload.on('progress', progress => {
    console.log(`So far we've uploaded ${progress.detail}% of this file.`);
  });

  upload.on('success', () => {
    console.log("Wrap it up, we're done here. 👋");
  });
};

API

createUpload(options)

Returns an instance of UpChunk and begins uploading the specified File.

options object parameters

  • endpoint type: string | function (required)

    URL to upload the file to. This can be either a string of the authenticated URL to upload to, or a function that returns a promise that resolves that URL string. The function will be passed the file as a parameter.

  • file type: File (required)

    The file you'd like to upload. For example, you might just want to use the file from an input with a type of "file".

  • headers type: Object

    An object with any headers you'd like included with the PUT request for each chunk.

  • chunkSize type: integer, default:5120

    The size in kb of the chunks to split the file into, with the exception of the final chunk which may be smaller. This parameter should be in multiples of 256.

  • maxFileSize type: integer

    The maximum size of the file in kb of the input file to be uploaded. The maximum size can technically be smaller than the chunk size, and in that case there would be exactly one chunk.

  • retries type: integer, default: 5

    The number of times to retry any given chunk.

  • delayBeforeRetry type: integer, default: 1

    The time in seconds to wait before attempting to upload a chunk again.

  • method type: "PUT" | "PATCH" | "POST", default: PUT

    The HTTP method to use when uploading each chunk.

UpChunk Instance Methods

  • pause()

    Pauses an upload after the current in-flight chunk is finished uploading.

  • resume()

    Resumes an upload that was previously paused.

UpChunk Instance Events

Events are fired with a CustomEvent object. The detail key is null if an interface isn't specified.

  • attempt { detail: { chunkNumber: Integer, chunkSize: Integer } }

    Fired immediately before a chunk upload is attempted. chunkNumber is the number of the current chunk being attempted, and chunkSize is the size (in bytes) of that chunk.

  • attemptFailure { detail: { message: String, chunkNumber: Integer, attemptsLeft: Integer } }

    Fired when an attempt to upload a chunk fails.

  • chunkSuccess { detail: { chunk: Integer, attempts: Integer, response: XhrResponse } }

    Fired when an indvidual chunk is successfully uploaded.

  • error { detail: { message: String, chunkNumber: Integer, attempts: Integer } }

    Fired when a chunk has reached the max number of retries or the response code is fatal and implies that retries should not be attempted.

  • offline

    Fired when the client has gone offline.

  • online

    Fired when the client has gone online.

  • progress { detail: [0..100] }

    Fired continuously with incremental upload progress. This returns the current percentage of the file that's been uploaded.

  • success

    Fired when the upload is finished successfully.

Credit

The original idea and base for this came from the awesome huge uploader project, which is what you need if you're looking to do multipart form data uploads. 👏

Also, @gabrielginter ported upchunk to Flutter.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].