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

@iclae0/big-file-upload

v0.0.2

Published

a big file upload tool

Downloads

13

Readme

big-file-upload

NPM version NPM downloads

Install

$ npm install @iclae0/big-file-upload

Use

最小可使用配置

Minimum Usable Configuration

import { BigFileUpload } from 'big-file-upload'

const bigFileUpload = new BigFileUpload(targetBigFile, {
  chunkUploadUrl: 'chunkUploadUrl',
  createChunkUploadParam: [
    ['reqParamChunkHash', 'chunkHash'],
    ['reqParamChunkSize', 'chunkSize'],
    ['reqParamTotal', 'totalCount'],
    ['reqParamFileHash', 'fileHash'],
    ['reqParamFileSize', 'fileSize'],
    ['reqParamFileName', 'fileName'],
    ['reqParamBinary', 'chunk']
  ],
  queryFileUploadStatusUrl: 'queryFileUploadStatusUrl',
  queryFileUploadStatusChunkHashKey: 'chunkHash',
  completeUrl: 'completeUrl',
  createCompleteParam: [
    ['fileHash', 'fileHash'],
    ['fileSize', 'fileSize'],
    ['fileName', 'fileName'],
    ['sliceCount', 'totalCount']
  ],
  chunkThreshold: 200,
  chunkSize: 20,
  onProgress(percent) {
  },
  onSuccess({ filePath, fileHash }) {
  },
  onError() {
  }
 });
bigFileUpload.upload();
// bigFileUpload.cancelUpload()

Options

chunkUploadUrl

分片上传url

chunkUploadSuccessCode

分片上传请求成功码 默认 200

chunkThreshold

分片阈值 单位 M 大于这个值才会上传

chunkSize

分片大小 M

queryFileUploadStatusUrl

查询已上传文件的状态,已经上传了多少分片 根据已经上传的 chunkHash 来断点续传

queryFileUploadStatusChunkHashKey

查询已上传文件请求返回的 key来取值,例如返回的数据是这样的 [{chunkHash: '1', name:'xx'}, {chunkHash: '2', name: 'yy'}] queryFileUploadStatusChunkHashKey 就填 chunkHash,默认为 chunkHash,如果数据符合要求可不填

queryFileUploadStatusSuccessCode

查询已上传文件请求成功码 默认 200

queryFileUploadStatusDataField

查询已上传文件请求取哪个字段 eg: {code:200, data:{uploaded: []}} 可填uploaded 默认没有直接取 data 值,所以 data 最好是array

completeUrl

合并文件请求 url

completeMethod

合并请求 method 'GET' | 'POST'

completeBodyType

合并请求 method为POST 时,请求的方式 'formData' | 'json'

completeSuccessCode

合并请求成功码 默认 200

completeDataField

合并请求取值字段 默认filePath eg: {code: 200, data:{filePath: 'xxxx'}}

uploadData

外部参数 配置后可在createChunkUploadParam和createCompleteParam中使用

createChunkUploadParam

分片上传参数, array 的第一个参数自己取, 第二个是固定的, 如果需要使用外部参数, 可在配置中增加 uploadData:{foo:1} 然后在这里增加一个['reqFoo', 'foo']

可用默认参数

  • fileHash: 文件 hash
  • fileName: 文件名
  • fileSize: 文件大小
  • totalCount: 总分片数
  • chunkSize: 分片大小
  • chunk: 分片文件
  • chunkIndex: 分片索引
  • chunkHash: 分片 hash

createCompleteParam

同createChunkUploadParam

可用默认参数

  • fileHash: 文件 hash
  • fileName: 文件名
  • fileSize: 文件大小
  • totalCount: 总分片数

onSpliting

开始分片回调

onSplitEnd

分片结束,可拿到 fileHash, (fileHash:string) => void;

onProgress

可拿到进度 分片上传完毕是 99 合并文件成功后是 100

onComplete

合并文件成功

onSuccess

上传成功 (fileUrl: string) => void;

onCancel

取消

onError

错误

LICENSE

MIT