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

@minto-ai/minio-obs-server

v1.0.11

Published

minio文件上传

Readme

本工具库用于处理文件上传至后端服务器。

安装

使用 pnpm 进行安装:

pnpm install @minto-ai/minio-obs-server

使用

示例代码

import minioObsServer from '@minto-ai/minio-obs-server'

// 配置全局参数
minioObsServer.config({
  getToken: () => '用户的token'
})

// 创建要上传的文件对象
const sourceFile = new File(['hello world'], 'hello.txt', { type: 'text/plain' })

// 创建上传实例
const uploadContext = minioObsServer.create({
  sourceFile,
  onProgress: (event) => {
    console.log(`Upload progress: ${event.percent}%`)
  },
  onSuccess: (event) => {
    console.log('Upload success:', event.fileInfo)
  }
})

// 取消上传示例
// uploadContext.abort()

全局配置

全局配置可通过 minioObsServer.config 方法进行设置,支持以下参数:

| 参数 | 类型 | 必填 | 默认值 | 描述 | | ---------- | -------------- | -------- | ------ | ----------------------------------------------------------------------- | | getToken | () => string | 是 | 无 | 用于获取上传所需的 token,该 token 用于身份验证,确保上传请求的合法性。 |

上传选项

创建上传实例时,可通过 minioObsServer.create 方法传入上传选项,支持以下参数:

| 参数 | 类型 | 必填 | 默认值 | 描述 | | ------------ | ------------------------------------------------------------------------- | -------- | ---------- | -------------------------------------------------------------------------------------------- | | sourceFile | File | 是 | 无 | 要上传的文件对象。 | | onStart | () => void | 否· | () => {} | 上传开始时的回调函数。 | | onProgress | (event: { percent: number }) => void | 否 | () => {} | 上传进度回调函数,event.percent 表示上传进度百分比。 | | onSuccess | (event: { sourceFile: File, fileInfo: IUploadFileSuccessFile }) => void | 否 | () => {} | 上传成功时的回调函数,event.sourceFile 为上传的文件对象,event.fileInfo 为文件上传信息。 | | onError | (error: Error) => void | 否 | () => {} | 上传失败时的回调函数,errorObsError错误对象。 | | onAbort | () => void | 否 | () => {} | 取消上传时的回调函数。 | | onFinally | () => void | 否 | () => {} | 上传结束时的回调函数,无论上传成功或失败都会触发。 |

取消上传

可通过调用上传实例的 abort 方法取消上传:

uploadContext.abort()

错误处理

工具库中定义了多种错误码,当上传过程中出现错误时,会抛出对应的 ObsError 对象,可通过 error.code 获取错误码,根据错误码进行相应的处理。错误码及其含义如下:

| 错误码 | 描述 | | ------- | ---------------------------- | | 10001 | 请求失败,请检查网络 | | 10007 | 文件上传取消失败,请检查网络 |

注意事项

  • 本工具库依赖 axios,请确保项目中已安装 axios,版本要求为 ^1.7.9
  • 在使用 getToken 方法获取 token 时,请确保返回的 token 是有效的,否则可能导致上传失败。