通用OBS文件上传
npm install @minto-ai/obs-server@minto-ai/obs-server 是一款统一的 OBS 文件上传工具库,旨在简化并高效处理文件上传任务。该工具库会通过后端的 file/config 接口获取 OBS 配置信息,进而自动判断使用 @minto-ai/huawei-obs-server 还是 @minto-ai/aws-obs-server来完成上传操作。
bash
pnpm install @minto-ai/obs-server
`
使用
示例代码
`js
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`)来决定。请参考对应工具库的文档进行准确配置。