@minto-ai/obs-server
v1.0.32
Published
通用OBS文件上传
Downloads
80
Readme
@minto-ai/obs-server 是一款统一的 OBS 文件上传工具库,旨在简化并高效处理文件上传任务。该工具库会通过后端的 file/config 接口获取 OBS 配置信息,进而自动判断使用 @minto-ai/huawei-obs-server 还是 @minto-ai/aws-obs-server来完成上传操作。
安装
pnpm install @minto-ai/obs-server使用
示例代码
import obsServer from '@minto-ai/obs-server'
// 配置全局参数
obsServer.config({
getToken: () => '用户的token',
fileSplitThreshold: 1024 * 1024 * 5
})
// 创建要上传的文件对象
const sourceFile = new File(['hello world'], 'hello.txt', { type: 'text/plain' })
// 创建上传实例
const uploadContext = obsServer.create({
sourceFile,
onProgress: (event) => {
console.log(`Upload progress: ${event.percent}%`)
},
onSuccess: (event) => {
console.log('Upload success:', event.fileInfo)
}
})
// 取消上传示例
// uploadContext.abort()
注意事项
- 在使用该工具库时,首先会调用
file/config接口来获取 OBS 的类型。若返回值为aws,则使用@minto-ai/aws-obs-server进行上传;若返回值为huawei,则使用@minto-ai/huawei-obs-server进行上传。 config和create等方法所需要的参数会根据具体使用的工具库(@minto-ai/aws-obs-server或@minto-ai/huawei-obs-server)来决定。请参考对应工具库的文档进行准确配置。
