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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@bnfe/oss-upload

v1.0.8

Published

oss-upload

Downloads

24

Readme

@bnfe/oss-upload

这是一个集成ali-oss上传的库

安装

pnpm install @bnfe/oss-upload -S

引入

import { AliOss } from "@bnfe/oss-upload";

使用

const aliOss = new AliOss({
  dir: "/sop",  // 上传文件目录 需要更改为你要上传的目录
  reqUrl: "", // 获取token的地址
});

export const OssUpload = async (file: File) => {
  try {
    const result: any = await aliOss.upload(file);

    return result.cdnUrl;
  } catch (error) {
    console.log("error", error);
    return new Error("上传失败");
  }
};

入参

type MultipartUploadParamsTypes = {
  parallel?: number; // 并行上传数量  默认为5
  partSize?: number; // 每片大小  默认1M
  checkpoint?: any; // 断点续传时需要的参数  为progress的checkpoint
  /**
   * 分片上传需要进度条时可以设置此参数
   * p 进度百分比(0~1之间的小数)
   * fileUrl 为 cdn返回的url
   * checkpoint记录本地分片上传结果的文件
   * res 单个分片上传成功返回的response。
   */
  progress?: (p: number, fileUrl: string, checkpoint?: any, res?: any) => void;
};

type OssPropsTypes = {
  /**
   * 请求token的地址  默认为根据环境变量获取  传入则根据传入使用
   * 传入时  该接口需返回
   * {
   *   data: {
   *    host: cdn地址
   *    region: 阿里云配置
   *    bucket: 阿里云配置
   *    stsToken: 获取临时的token  临时token需要为STS
   *    accessKeyId: 获取临时的accessKeyId
   *    accessKeySecret: 获取临时的accessKeySecret
   *    expiration: 获取临时的expiration
   *   }
   * }
   */
  reqUrl: string;
  // 文件夹名称  默认为 public  传入时不加 /
  dir?: string;
  // token过期时间  ms  默认为1小时  3600  60*60
  expire?: number;
  /** 超过多大开启分片上传 默认为 100MB   100 * 1024 * 1024 */
  multipartUploadSize?: number;
  multipartUploadParams?: MultipartUploadParamsTypes;
};

Upload方法入参


  type uploadProps = {
    file: File,  // 文件
    /**
     * 文件名,传入直接使用name,不拼接dir    
     * 默认会使用dir+日期+uuid(6位)+文件名
     */
    name?: string, 
    // 分片上传需要参数 
    multipartUploadParams?: MultipartUploadParamsTypes
  }

出参

type ResParamsTypes = {
  cdnUrl: string; // url 为cdn返回的url
  ossUrl: string; // ossUrl为oss返回的url
  name: string; // 文件名
  ossResParams: any; // oss返回的参数
};

ali-oss

参考文档

客户端直传-官方文档

nodejsSDK

git文档