# 对象存储
# 获取用户云盘大小
功能:获取用户云盘空间占用大小,单位字节。
路径:oss/bs/user/size
。
请求方法:GET
。
请求参数:
参数 | 必须 | 类型 | 备注 |
---|---|---|---|
appUserIdList | 是 | string[] | 业务用户 ID 列表 |
请求示例:
点击查看
/**
* 获取用户云盘空间占用大小,单位字节。
* @param appUserIdList 业务用户 ID 列表
*/
export async function GET(
appUserIdList: string[]
): Promise<ResponseBody<{ appUserId: string; size: number }[]>> {
const method = 'GET'
const path = '/fs/bs/user/size'
const { nonce, timestamp } = genNonce()
const signature = sign(method, path, nonce, timestamp)
const Authorization = authorization(signature)
const headers = {
Authorization,
nonce,
timestamp,
}
const params = {
appUserIdList,
}
const resp = await axios.get(path, {
headers,
params,
paramsSerializer: (params) => qs.stringify(params),
})
return resp.data
}
响应示例:
点击查看
{
"code": 0,
"message": "success",
"data": [
{
"appUserId": "dev-docs-001",
"size": 26
}
]
}
# 获取上传链接
功能:
获取对象存储服务(简称:OSS)上传防盗链,通过这个链接可以将文件上传到 OSS。
文档中插入附件、图片等多媒体元素,必须先将文件上传到 OSS。
路径:oss/bs/private/object
。
请求方法:PUT
。
请求参数:
参数 | 必须 | 类型 | 备注 |
---|---|---|---|
objectId | 是 | string | OSS 对象 ID |
fid | 是 | string | 文件 ID |
appUserId | 是 | string | 业务用户 ID |
注意
objectId
由两部分组成。
前缀表示文件的类型,目前有 image
表示图片, attachment
表示附件, shorthand
表示录音速记的音频。
后缀由 uuid
和文件后缀名组成。
如:image/{uuid}.jpg
。
请求示例:
点击查看
export async function PUT(
objectId: string,
fid: string,
appUserId: string
): Promise<ResponseBody<{ safetyChain: string }>> {
const method = 'PUT'
const path = '/oss/bs/private/object'
const { nonce, timestamp } = genNonce()
const signature = sign(method, path, nonce, timestamp)
const Authorization = authorization(signature)
const headers = {
Authorization,
nonce,
timestamp,
}
const data = {
objectId,
fid,
appUserId,
}
const resp = await axios.put(path, data, {
headers,
})
return resp.data
}
响应示例:
点击查看
{
"code": 0,
"message": "success",
"data": {
"safetyChain": "https://bjbdn.openstorage.cn/v1/agji/c1/image/b457a945-fe1c-4546-938c-27e58eb21d25.jpg?token=1c64554f46dacd176d2e1cb804fcafb150a903e6&e=1666862949"
}
}
# 获取下载链接
功能:
获取 OSS 下载防盗链。
通过这个链接可以直接从 OSS 下载文件,或者给 <img>
标签的 src
属性赋值以展示图片。
路径:oss/bs/private/object
。
请求方法:GET
。
请求参数:
参数 | 必须 | 类型 | 备注 |
---|---|---|---|
objectId | 是 | string | OSS 对象 ID |
fid | 是 | string | 文件 ID |
uid | 是 | number | 讯飞文档用户 ID |
图片缩略服务:
对于常见格式的图片,OSS 提供图片缩略服务,可通过传递额外参数启用。
以下图片参数同时最多只有一个生效,优先级从高到低。
参数 | 必须 | 类型 | 备注 | 示例 |
---|---|---|---|---|
imageParam.scalingProportion | 否 | number | 缩放比例,取值 10-1000,100 为原图。 | 10 |
imageParam.scalingWidth | 否 | number | 宽度按像素值定长,高度按比例缩放。 | 1024 |
imageParam.scalingHeight | 否 | number | 高度按像素值定长,宽度按比例缩放。 | 768 |
请求示例:
点击查看
export async function GET(
objectId: string,
fid: string,
appUserId: string
): Promise<ResponseBody<{ safetyChain: string }>> {
const method = 'GET'
const path = '/oss/bs/private/object'
const { nonce, timestamp } = genNonce()
const signature = sign(method, path, nonce, timestamp)
const Authorization = authorization(signature)
const headers = {
Authorization,
nonce,
timestamp,
}
const params = {
objectId,
fid,
appUserId,
}
const resp = await axios.get(path, {
params,
paramsSerializer: (params) => qs.stringify(params),
headers,
})
return resp.data
}
响应示例:
点击查看
{
"code": 0,
"message": "success",
"data": {
"safetyChain": "https://bjbdn.openstorage.cn/v1/agji/c1/image/b457a945-fe1c-4546-938c-27e58eb21d25.jpg?token=3eda70238aeee3b0bcfd12f895684dbc33281d99&e=1666862949"
}
}
# 获取云盘文件上传链接
功能:
上传云盘文件,支持全量上传和分片上传。
路径:oss/bs/storage/object
。
请求方法:PUT
。
请求参数:
参数 | 必须 | 类型 | 备注 |
---|---|---|---|
appUserId | 是 | string | 业务用户 ID |
parentFid | 是 | string | 上级文件夹 ID |
desAppUserId | 是 | string | 上传到的空间所有者业务用户 ID |
name | 是 | string | 上传文件名 |
partNum | 否 | number | 分片号 0000-9999,从 0000 开始递增,建议 20M 以上文件使用分片上传,每片 20M。例如 0001 |
fid | 否 | string | 文件唯一标识(分片上传第二片及以后需要此传参,获取第一片临时链会返回此参数) |
objectId | 否 | string | 存储对象唯一标识(分片上传第二片及以后需要此传参,获取第一片临时链会返回此参数) |
注意
objectId
由两部分组成。
前缀表示文件的类型,云盘文件使用 storage
。
后缀由 uuid
和文件后缀名组成。
如:storage/aac7c49e-c8da-4cc5-a5a3-803d37582027.jpg
。
参数示例:
{
"appUserId": "006",
"desAppUserId": "006",
"name": "111.zip",
"parentFid": "0",
"partNum": "0001",
"fid": "Zwz",
"objectId": "storage/c9972f49-88d1-490c-b3e9-275b3fab1741.zip"
}
请求示例:
点击查看
/**
* 获取上传云盘文件的临时链接。
* @param parentFid 上级文件夹 ID,如果为顶级则传 0。
* @param name 文件名称
* @param appUserId 创建者业务用户 ID
* @param desAppUserId 拥有者业务用户 ID
* @param options 分片上传参数
*/
export async function PUT(
parentFid: string,
name: string,
appUserId: string,
desAppUserId: string,
options?:
| { partNum: '0000' }
| { partNum: string; fid: string; objectId: string }
): Promise<ResponseBody<IflydocsFileUploadInfo>> {
const method = 'PUT'
const path = '/oss/bs/storage/object'
const { nonce, timestamp } = genNonce()
const signature = sign(method, path, nonce, timestamp)
const Authorization = authorization(signature)
const headers = {
Authorization,
nonce,
timestamp,
}
const data = {
parentFid,
name,
appUserId,
desAppUserId,
...options,
}
const resp = await axios.put(path, data, {
headers,
})
return resp.data
}
响应示例:
点击查看
{
"code": 0,
"message": "success",
"data": {
"fid": "10tdp",
"safetyChain": "https://bjbdn.openstorage.cn/v1/agji/c1/storage/9922c20d-3891-4926-b9fd-5945ac8cc52d?token=1120e32e326363efe0b79f594dbc363cc54f983e&e=1666862950",
"objectId": "storage/9922c20d-3891-4926-b9fd-5945ac8cc52d",
"requestId": "02b45c3f5bda4c7ca6eb6a2bb9600fff"
}
}
# 获取云盘文件分片清单
功能:
获取云盘文件(通过分片上传方式上传的文件)分片清单,可查看、核对每一片文件的相关信息。
路径:oss/bs/storage/object/manifest
。
请求方法:GET
。
请求参数:
参数 | 必须 | 类型 | 备注 |
---|---|---|---|
appUserId | 是 | string | 业务用户 ID |
fid | 否 | string | 文件 ID |
objectId | 否 | string | 存储对象 ID |
请求示例:
点击查看
export async function GET(objectId: string, fid: string, appUserId: string) {
const method = 'GET'
const path = '/oss/bs/storage/object/manifest'
const { nonce, timestamp } = genNonce()
const signature = sign(method, path, nonce, timestamp)
const Authorization = authorization(signature)
const headers = {
Authorization,
nonce,
timestamp,
}
const params = {
objectId,
fid,
appUserId,
}
const resp = await axios.get(path, {
params,
paramsSerializer: (params) => qs.stringify(params),
headers,
})
return resp.data
}
响应示例:
点击查看
```jsonc
//#region put
{
"code": 0,
"message": "success",
"data": {
"fid": "10tdt",
"safetyChain": null,
"objectId": "storage/5d98619e-1d89-4241-aeb6-7162cd3210d7.txt",
"requestId": "4493a6a607fa4452bd878fa42426ef86"
}
}
//#endregion put
```
```jsonc
//#region delete
{
"code": 0,
"message": "success",
"data": null
}
//#endregion delete
```
# 提交云盘文件分片清单
功能:
提交分片文件清单以生成云盘文件,对象存储服务将分片文件整合为一个完整文件。
路径:oss/bs/storage/object/manifest
。
请求方法:PUT
。
请求参数:
参数 | 必须 | 类型 | 备注 |
---|---|---|---|
appUserId | 是 | string | 业务用户 ID |
fid | 否 | string | 文件 ID |
objectId | 否 | string | 存储对象 ID |
请求示例:
点击查看
export async function PUT(objectId: string, fid: string, appUserId: string): Promise<ResponseBody<IflydocsFileUploadInfo>> {
const method = 'PUT'
const path = '/oss/bs/storage/object/manifest'
const { nonce, timestamp } = genNonce()
const signature = sign(method, path, nonce, timestamp)
const Authorization = authorization(signature)
const headers = {
Authorization,
nonce,
timestamp,
}
const data = {
objectId,
fid,
appUserId,
}
const resp = await axios.put(path, data, {
headers,
})
return resp.data
}
响应示例:
点击查看
{
"code": 0,
"message": "success",
"data": {
"fid": "10tdt",
"safetyChain": null,
"objectId": "storage/5d98619e-1d89-4241-aeb6-7162cd3210d7.txt",
"requestId": "4493a6a607fa4452bd878fa42426ef86"
}
}
# 清除云盘分片文件
功能:
清除未提交清单的分片文件。
路径:oss/bs/storage/object/manifest
。
请求方法:DELETE
。
请求参数:
参数 | 必须 | 类型 | 备注 |
---|---|---|---|
appUserId | 是 | string | 业务用户 ID |
fid | 否 | string | 文件 ID |
objectId | 否 | string | 存储对象 ID |
请求示例:
点击查看
export async function DELETE(objectId: string, fid: string, appUserId: string) {
const method = 'DELETE'
const path = '/oss/bs/storage/object/manifest'
const { nonce, timestamp } = genNonce()
const signature = sign(method, path, nonce, timestamp)
const Authorization = authorization(signature)
const headers = {
Authorization,
nonce,
timestamp,
}
const params = {
objectId,
fid,
appUserId,
}
const resp = await axios.delete(path, {
headers,
data: params,
})
return resp.data
}
响应示例:
点击查看
{
"code": 0,
"message": "success",
"data": null
}
# 获取文件关联存储对象信息
功能:
查询文档中所有图片、附件信息和下载链接。
路径:oss/bs/file/oss
。
请求方法:GET
。
请求参数:
参数 | 必须 | 类型 | 备注 |
---|---|---|---|
fid | 否 | string | 文件 ID |
请求示例:
点击查看
type OSSObjectInfo = {
ossObject: IflydocsOSSObject
safetyChain: string
}
export async function GET(
fid: string
): Promise<ResponseBody<null | OSSObjectInfo[]>> {
const method = 'GET'
const path = '/oss/bs/file/oss'
const { nonce, timestamp } = genNonce()
const signature = sign(method, path, nonce, timestamp)
const Authorization = authorization(signature)
const headers = {
Authorization,
nonce,
timestamp,
}
const params = {
fid,
}
const resp = await axios.get(path, {
params,
paramsSerializer: (params) => qs.stringify(params),
headers,
})
return resp.data
}
响应示例:
点击查看
{
"code": 0,
"message": "success",
"data": [
{
"ossObject": {
"objectId": "image/dad2003a-8928-439f-b552-8d620f27649b.jpg",
"owner": 1657589576821,
"container": "c1",
"fid": "10tdn",
"appId": "6da37dd3",
"createTime": 1666859348759,
"creator": 1657589576821,
"modifyTime": 1666859348759,
"modifier": 1657589576821,
"size": 0,
"copyFrom": null,
"time": null
},
"safetyChain": "https://bjbdn.openstorage.cn/v1/agji/c1/image/dad2003a-8928-439f-b552-8d620f27649b.jpg?token=72eedb64f266fc122bbb854559fca15a37daf734&e=1666862949"
}
]
}