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

react-native-chunk-upload

v2.0.3

Published

A package to bring Chunked File Upload / Resumable File Upload into React Native. Split a large file into multiple smaller pieces then upload them without worrying about network disconnection, even if it happens React Native Chunk Upload will only upload

Downloads

231

Readme

React Native Chunk Upload 2.x

React-Native-Chunk-Upload

A package to bring Chunked File Upload / Resumable File Upload into React Native. Split a large file into multiple smaller pieces then upload them without worrying about network disconnection, even if it happens React Native Chunk Upload will only upload the failed chunk not the whole file!

Changelog

In v1.x we had to first break the whole file into smaller pieces and then start uploading them.
But in v2.x this problem has been fixed. In addition, the speed of this process has increased 10 times.

You may want to take a look at the Schema section.

Dependencies

⚠ Make sure the following packages are installed.

  • react-native-fs https://github.com/itinance/react-native-fs
  • rn-fetch-blob https://github.com/joltup/rn-fetch-blob

Installation

  • via NPM

    npm i react-native-chunk-upload
  • via Yarn

    yarn add react-native-chunk-upload

Basic Usage

import Axios from 'axios';
import ChunkUpload from 'react-native-chunk-upload';

const chunk = new ChunkUpload({
    path: response.path, // Path to the file
    size: 10095, // Chunk size (must be multiples of 3)
    fileName: response.fileName, // Original file name
    fileSize: response.size, // Original file size

    // Errors
    onFetchBlobError: (e) => console.log(e),
    onWriteFileError: (e) => console.log(e),
});

chunk.digIn(this.upload.bind(this));

upload(file, next, retry, unlink) {
    const body = new FormData();

    body.append('video', file.blob); // param name

    Axios.post('❌ URL HERE ❌', body, {
        headers: {
            "Content-Type": "multipart/form-data",
            "Accept": 'application/json',

            // 💥 Choose one of the following methods:

            // 1️⃣ If you're using the wester-chunk-upload php library...
            ...file.headers,

            // 2️⃣ Customize the headers
            "x-chunk-number": file.headers["x-chunk-number"],
            "x-chunk-total-number": file.headers["x-chunk-total-number"],
            "x-chunk-size": file.headers["x-chunk-size"],
            "x-file-name": file.headers["x-file-name"],
            "x-file-size": file.headers["x-file-size"],
            "x-file-identity": file.headers["x-file-identity"]
        }
    })
        .then(response => {
            switch (response.status) {
                // ✅ done
                case 200:

                    console.log(response.data);
                    
                break;

                // 🕗 still uploading...
                case 201:
                    console.log(`${response.data.progress}% uploaded...`);

                    next();
                break;
            }
        })
        .catch(error => {
            // ❌ waddafuk? 😟
            if (error.response) {
                if ([400, 404, 415, 500, 501].includes(error.response.status)) {
                    console.log(error.response.status, 'Failed to upload the chunk.');

                    unlink(file.path);
                } else if (error.response.status === 422) {
                    console.log('Validation Error', error.response.data);
                    
                    unlink(file.path);
                } else {
                    console.log('Re-uploading the chunk...');

                    retry();
                }
            } else {
                console.log('Re-uploading the chunk...');

                retry();
            }
        });
}

Wester Chunk Upload PHP Library

If you're going to use this library, you won't need much to do...

// easy peasy, right? 😁
headers: {
    "Content-Type": "multipart/form-data",
    "Accept": 'application/json',

    ...file.headers
}
  • https://github.com/hossein-zare/wester-chunk-upload

Schema

chunk.digIn(
    (
        file: {
            path: string,
            headers: {
                "x-chunk-number": number,
                "x-chunk-total-number": number,
                "x-chunk-size": number,
                "x-file-name": string,
                "x-file-size": number,
                "x-file-identity": string
            },
            blob: {
                name: string,
                type: string,
                uri: string
            }
        },
        next: () => void,
        retry: () => void,
        unlink: (path: string) => void
    ): void
): void;

Support Us

Just star the repository, that's it! 😉