Custom Multi-Part File Uploader

Create your own file uploader quickly and efficiently using ready-coded methods. This help you can implement multi-part upload flows with pause, resume, and cancel functions.

Try it yourself:

In this demo, we use upload method to upload files. This method to upload files especially with Filestack’s Content Ingestion (CIN) and Filestack Intelligent Ingestion (FII).

The file uploading can be paused, resumed, or cancelled. To achieve this we should should set token with methods that pause, cancel or resume uploads.

Terminal

npm install filestack-js tslib

HTML


    

JavaScript (index.mjs)

import "./styles.css";
import * as filestack from "filestack-js";

//Replace Your_API_key with you API Key from DevPortal dev.filestack.com/login/
const client = filestack.init("Your_API_key");

const onProgress = (evt) => {
  document.getElementById("progress").innerHTML = `${evt.totalPercent}%`;
};

document.getElementById("file").addEventListener("change", (event) => {
  const files = event.target.files[0];

  const UploadOptions = {
    concurrency: 5, //Maximum amount of part jobs to run concurrently. Default is 3.
    disableIntegrityCheck: true, //Disable checking integrity of uploaded files. On slower devices it can boost upload performance (disable counting md5 from file parts)
    intelligent: false, //Enable/disable intelligent ingestion. If truthy then intelligent ingestion must be enabled in your Filestack application. Passing true/false toggles the global intelligent flow (all parts are chunked and committed). Passing 'fallback' will only use FII when network conditions may require it (only failing parts will be chunked).
    intelligentChunkSize: 5 * 1024 * 1024, // Set the default intiial chunk size for Intelligent Ingestion. Defaults to 8MB on desktop and 1MB on mobile.

    partSize: 6 * 1024 * 1024, //Maximum size for file slices. Is overridden when intelligent=true. Default is (6MB).
    progressInterval: 10000, //How often to report progress. Default is 1000 (in milliseconds).
    onProgress,
    onRetry: () => {
      console.log("Retry uploading");
    },
    retry: 3, // Retry limit. Default is 10.
    retryFactor: 2, //Factor for exponential backoff on server errors. Default is 2.
    retryMaxTime: 15000, //Upper bound for exponential backoff. Default is 15000.
    timeout: 200000, //Timeout for network requests. Default is 120000.
    tags: {
      tagWord: "Tag Word",
    },
  };

  const StoreUploadOptions = {
    altText: " Alternative keyword",
    filename: "This-is-the-name-of-the-file",
    //mimetype,
    //sanitizer: SanitizeOptions;
    //workflows: (string | WorkflowConfig)[];
  };

  const token = {};

  client
    .upload(files, UploadOptions, StoreUploadOptions, token)
    .then((res) => {
      console.log("success: ", res);
    })
    .catch((err) => {
      console.log(err);
    });

  document.getElementById("cancel").addEventListener("click", () => {
    token.cancel();
    document.getElementById(
      "progress"
    ).innerHTML = `File upload has been canceled`;
  });

});

Start building your own file upload solution today.

PREVIEW

Users can preview their uploaded files directly inside the File Picker.

CONNECT TO 20+ CLOUD DRIVES

Connect your app directly to AWS, Facebook, Dropbox, Instagram, and more.

PROGRESS BAR UPLOADS

Give your users confidence that their files are on the way to the right destination.

MULTI-FILE UPLOADS

Let your users upload multiple files at one time for speed and simplicity.

CUSTOM CSS

Filestack blends seamlessly into your website or app. Ask about white-labeling.

CLIENT-SIDE CROP

Users can crop files to perfection before sending them to your website or app.

UNLIMITED UPLOADING

Upload any file type, from any local or cloud source, at any scale.

WEBSITES & HTML

Filestack can even load web content from any public URL and capture the rendered page as an image. Perfect for generating screenshots, previews, or converting HTML-based content into other formats.

SECURE CLOUD STORAGE

Store uploads directly in your cloud storage for ease and accessibility.

“Being smart here, in my opinion, is seriously looking at Filestack to give you a fantastic uploading experience, while you spend your time on your product vision, not already-solved problems.”

— CHRIS COYIER, FOUNDER OF CSS-TRICKS & CODEPEN