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

easy-file-uploader-server

v1.0.5

Published

后端通用文件分片上传组件

Downloads

8

Readme

easy-file-uploader-server

通用文件上传组件server端,提供了开箱即用的server端的接收文件方法。

server端使用方式

使用 npm 或 yarn 安装依赖

npm install easy-file-uploader-server
yarn add easy-file-uploader-server

在需要实现文件上传的后端逻辑中实例化FileUploaderServer

FileUploaderServer可以接收如下配置项:

interface IFileUploaderOptions {
  tempFileLocation: string; // 储存文件切片的路径
  mergedFileLocation: string; // 储存合并后文件的路径
}

在实例化FileUploaderServer后,可以使用FileUploaderServer提供的如下方法:

/**
 * 获取配置项
 */
getOptions(): IFileUploaderOptions;

/**
 * 初始化文件分片上传,实际上就是根据fileName和时间计算一个md5,并新建一个文件夹
 * @param fileName 文件名
 * @returns 上传Id
 */
initFilePartUpload(fileName: string): Promise<string>;

/**
 * 上传分片,实际上是将partFile写入uploadId对应的文件夹中,写入的文件命名格式为`partIndex|md5`
 * @param uploadId 上传Id
 * @param partIndex 分片序号
 * @param partFile 分片内容
 * @returns 分片md5
 */
uploadPartFile(uploadId: string, partIndex: number, partFile: Buffer): Promise<string>;

/**
 * 获取已上传的分片信息,实际上就是读取这个文件夹下面的内容
 * @param uploadId 上传Id
 * @returns 已上传的分片信息
 */
listUploadedPartFile(uploadId: string): Promise<IUploadPartInfo[]>;

/**
 * 取消文件上传,硬删除会直接删除文件夹,软删除会给文件夹改个名字
 * @param uploadId 上传Id
 * @param deleteFolder 是否直接删除文件夹
 */
cancelFilePartUpload(uploadId: string, deleteFolder?: boolean): Promise<void>;

/**
 * 完成分片上传,实际上就是将所有分片都读到一起,然后进行md5检查,最后存到一个新的路径下。
 * @param uploadId 上传Id
 * @param fileName 文件名
 * @param md5 文件md5
 * @returns 文件存储路径
 */
finishFilePartUpload(uploadId: string, fileName: string, md5: string): Promise<IMergedFileInfo>;

使用样例

使用样例可以看这个组件:使用样例链接