How to Download Files Using Javascript | JS File Downloader

JS File Downloader is a simple, no-dependency library that will be able to download the file from the browser and show the download status.

How to make use of it:

1. Install & download the package deal.

# NPM
$ npm install js-file-downloader --save

2. Import the file downloader as a module.

import Downloader from 'js-file-downloader';

3. Or load them js-file-downloader.min.js from the dist folder.

<script src="./dist/js-file-downloader.min.js"></script>

4. Create a new downloader instance that specifies the path to the file to be downloaded.

new jsFileDownloader({ 
    url: '1.jpg' 
})

5. Do one thing when the download is ended.

new jsFileDownloader({ 
    url: '1.jpg' 
})
.then(function () {
  alert('File downloaded');
});

6. Do one thing when an error occurred.

new jsFileDownloader({ 
    url: '1.jpg' 
})
.catch(function (error) {
  // do something
});

7. Determine the most time to wait earlier than stopping downloading.

new jsFileDownloader({ 
    url: '1.jpg',
    timeout: 50000
});

8. Determine whether or not to disable download on mobile gadgets.

new jsFileDownloader({ 
    url: '1.jpg',
    mobileDisabled: false
})

9. Determine whether or not to auto begin downloading on web page load.

new jsFileDownloader({ 
    url: '1.jpg',
    autoStart: false
});

10. Determine whether or not to drive desktop mode even on mobile gadgets for downloading information.

new jsFileDownloader({ 
    url: '1.jpg',
    forceDesktopMode: true
});

11. Customize the request header data.

new jsFileDownloader({ 
    url: '1.jpg',
    headers: [
      { name: 'Authorization', value: 'Value...' }
    ]
});

12. Customize the file title.

new jsFileDownloader({ 
    url: '',
    filename: ''
});

13. Check download status utilizing the process function.

new jsFileDownloader({ 
    url: '1.jpg',
    process: process
});

function process (event) {
  if (!event.lengthComputable) return;
  var downloadingPercentage = Math.floor(event.loaded / event.total * 100);
  // what to do ...
};

14. Determine the strategy for the HTTP request.

new Downloader({ 
    url: '...',
    method: 'POST' // "GET", "POST", "PUT"
})

15. Customize the ultimate file title with the nameCallback.

new Downloader({ 
    nameCallback: function(name) {
      return 'i-am-prefix-' + name;
    }
})

File Downloader With Promise Support, JS File Downloader Github, File Downloads in the Browser


See Demo And Download

Official Website(AleeeKoi): Click Here

This superior jQuery/javascript plugin is developed by AleeeKoi. For extra Advanced usage, please go to the official website.

Related Posts

Confetti-Falling-Animation-Effect-party

Confetti Falling Animation Effect In JavaScript | party.js

Party.js is a JavaScript library to brighten user site experience with visual effects! Celebrate success with dom confetti! The library is written in TypeScript and compiled into…

jquery-cookie-consent

Simple jQuery Cookie Consent Plugin

jquery.cookie-consent is a simple jQuery plugin to request consent to use cookies. An easy-to-use and highly customizable cookie consent bar that informs your visitors of the use…

Timepicker-Plugin-for-jQuery

Timepicker JavaScript Plugin for jQuery Inspired by Google Calendar

jquery.timepicker is a lightweight jQuery timer plugin inspired by Google Calendar. It supports both mouse and keyboard navigation and weighs 5.5KB minified and compact. Features: Highly customizable…

angular-ngx-carousel-slider

A Lightweight, Touchable, and Responsive Angular Universal Carousel Library

ngxCarousel is a lightweight, tactile, and responsive library for creating an angular carousel. No dependencies, no more hammer. Must Read: Angular Responsive Image Slider With Lightbox Popup…

vue-fullpage-modal

First Mobile Full-screen Modal Popup Library For Vue

Vue full-page modal is a responsive, mobile-compatible, screen-friendly pop-up library for Vue.js. Must Read: Modal Component Is Written in Vanilla JS | ensemble Modal How to make…

random-number-picker

Generate a Random Number Picker In Vanilla JavaScript

Random Number Picker is a Vanilla JS-based number picker that allows you to generate a random number within a specified range. Must Read: Generating Lottery Numbers Using…