@lx-frontend/wx-upload-file
小程序文件上传库(仅支持上传,需单独获取上传配置)
Usage
在小程序中:
- 引入包
import { fileUpload } from '@lx-frontend/wx-upload-file'
上传图片
wx.chooseImage({
'sizeType': ['compressed'],
success: async (res) => {
const [ localPath ] = res.tempFilePaths
const upRes = await fileUpload({
uploadUrl: 'https://a.b.com/v1/storage',
uploadPath: 'a/image/2024-01-09/eubryuzf',
uploadToken: 'bearer ey11111',
uploadType: 'image'
filePath: localPath
})
console.log('upRes', upRes)
}
})
返回数据格式:
{
"code":0,
"data":[
{
"image":"https://xxxxx.png",
"key":"",
"thumbnail_image":"https://xxxx.png?x-oss-process=image/resize,w_300/quality,q_80",
"upload_image":"https://test-images-cdn.lxusercontent.com/xxxx.png"
}
],
"message":"ok"
}
参数说明
参数 | 说明 | 类型 | 可选值 | 默认值 | 必填 |
---|---|---|---|---|---|
uploadUrl | 上传服务url | String | - | - | 是 |
uploadPath | 上传存储path | String | - | - | 是 |
uploadToken | 上传token | String | - | - | 是 |
uploadType | 上传资源类型 | String | image/video/audio | - | 是 |
filePath | 小程序为选取资源的 tempFilePaths 字段 |
String | - | - | 是 |
customParams | 自定义参数 | String | - | - | 否 |
cb | uploadTask 回调 | String | - | - | 否 |