@sid-max1996/upload
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

@sid-max1996/upload

Usage

Node js file upload package with the ability to limit the download speed, tracking download progress and continue downloading from where it stopped.

Example

const { Uploader } = require('@sid-max1996/upload');
const fs = require('fs');
const path = require('path');
const ProxyAgent = require('proxy-agent');

const url = 'https://klike.net/uploads/posts/2019-07/1564314090_3.jpg';
const uploadDir = path.join(__dirname, 'download');
if (!fs.existsSync(uploadDir)) {
  fs.mkdirSync(uploadDir);
}

const uploader = new Uploader({
  // byteLimit: 500, // bytes per second limit for download
  // proxyAgent: ProxyAgent('http://51.91.157.66:80'), // to use proxy
  uploadDir, // path to the folder where files are uploaded
  // continueUploading: true, // continue downloading from where it stopped
  // headers: { 'User-Agent': 'App' },
  // timeoutMs: 5000
});
// uploader.emitter.on('debug', text => console.log(text));
uploader.emitter.on('log', (text) => console.log(text));
// tracking download progress
uploader.emitter.on('progress', (value) => console.log(`Progress (value: ${value}).`));

async function start() {
  const filePath = await uploader.upload({
    url,
    // uploadDir: __dirname, // change uploaded file dir
    // fileName: 'hello.jpg', // change uploaded file name
    // filePath: path.join(uploadDir, 'hello1.jpg'), // change uploaded file path
    // continueUploading: true, // change continue downloading from where it stopped
    // headers: { 'User-Agent': 'App' }
  });
  console.log(`Uploaded (path: ${filePath}).`);
  uploader.emitter.removeAllListeners(); // remove all event subscriptions
}

start();

Package Sidebar

Install

npm i @sid-max1996/upload

Weekly Downloads

5

Version

1.1.1

License

ISC

Unpacked Size

30.9 kB

Total Files

22

Last publish

Collaborators

  • sid-max1996