文件操作
文件查询与数据表查询方法一致,但只支持以下指定字段的筛选
支持字段 | 类型 | 说明 |
---|---|---|
id | String | 文件 id |
name | String | 文件名 |
size | Number | 文件大小,以字节为单位 |
category_id | String | 文件分类 id |
category_name | String | 文件分类名 |
created_at | Integer | 创建时间 (格式为 unix 时间戳) |
文件操作
实例化一个 BaaS.File
对象,以下操作都是在该对象上进行操作,如下进行实例化:
let MyFile = new BaaS.File()
上传文件
MyFile.upload(uploadFile, fileMeta)
参数说明
参数 | 类型 | 必填 | 说明 | 默认值 |
---|---|---|---|---|
uploadFile | String or Buffer | Y | 需要上传的文件 | 无 |
fileMeta | Object | N | 文件 meta 信息,如文件名,分类 ID 等 |
|
FileMeta对象说明
字段名 | 类型 | 必填 | 说明 | 默认值 |
---|---|---|---|---|
category_id | String | N | 文件分类 ID | '' |
random_file_link | Boolean | N | 是否使用随机的文件存储路径,值为 | true |
filename | String | N | 文件名 | file.bin |
filepath | String | N | 文件路径 | /tmp/file.bin |
contentType | String | N | 文件 MIME 类型 | application/octet-stream |
info
random_file_link
举例说明:
fileMeta.random_file_link
为true
时,如果fileMeta.filename
为avatar.png
, 则返回值中 res.data.file.path 为https://cloud-minapp-xxx.cloud.ifanrusercontent.com/1j6ZGvnzSpJ7YBZ8.png
fileMeta.random_file_link
为false
时,如果fileMeta.filename
为avatar.png
, 则返回值中 res.data.file.path 为https://cloud-minapp-xxx.cloud.ifanrusercontent.com/avatar.png
示例代码
返回参数说明
res.data:
参数 | 类型 | 说明 |
---|---|---|
path | String | 上传成功后的访问地址 URL |
file | Object | 包含文件详细信息,详见以下 |
file 参数说明:
参数 | 类型 | 说明 |
---|---|---|
path | String | 上传成功后的访问地址 URL |
cdn_path | String | 文件在 CDN 中的相对路径 |
created_at | String | 文件上传时间 |
id | Object | 文件 ID |
mime_type | String | 文件媒体类型 |
name | String | 文件名 |
size | Number | 以字节为单位 |
文件云下载
info SDK >= 3.8
创建下载任务
MyFile.createDownloadTask({originalUrl, filename, categoryName, overwrite})
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
originalUrl | String | Y | 需要下载的文件 URL |
filename | String | Y | 文件名 |
categoryName | String | N | 文件分类名 |
overwrite | Boolean | N | 是否覆盖已存在的同名文件, 默认值为 true |
示例代码
返回示例
获取下载结果
MyFile.getDownloadTaskResult(id)
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
id | Integer | Y | 下载任务 ID |
示例代码
返回示例
下载中:
下载失败:
下载成功:
获取文件详情
MyFile.get(fileID)
参数说明
| 参数 | 类型 | 必填 | 说明 | | :----- | :-- -- | :-- | :-- | | fileID | String | Y | 文件 id |
返回参数说明
res.data:
参数 | 类型 | 说明 |
---|---|---|
category | Object | 包含文件分类信息,详见以下 |
created_at | String | 文件上传时间 |
id | Object | 文件 ID |
mime_type | String | 文件媒体类型 |
name | String | 文件名 |
path | String | 文件路径 |
size | Number | 以字节为单位 |
category 参数说明:
参数 | 类型 | 说明 |
---|---|---|
id | String | 分类 ID |
name | String | 分类名 |
示例代码
返回示例
删除文件
MyFile.delete(fileID)
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
fileID | String or String Array | Y | 文件 id (可为数组) |
示例代码
info 删除单个文件,如果权限不足,会返回 401;删除多个文件,如果权限不足,则直接跳过该文件
获取符合条件的文件总数
BaaS.File#count()
{{filter()}}
查询,获取文件列表
BaaS.File#find(options)
参数说明
options:
参数 | 类型 | 必填 | 默认 | 说明 |
---|---|---|---|---|
withCount | boolean | 否 | true | 是否返回 total_count |
{{totalCount.withCountTips()}}
{{filter()}}
示例代码
排序
文件查询排序与数据表排序方法一致,但只支持对以下指定字段进行排序
支持字段 | 类型 | 说明 |
---|---|---|
name | String | 文件名 |
size | Number | 文件大小,以字节为单位 |
created_at | Number | 文件上传时间 |
示例代码
分页
文件查询排序与数据表分页方法一致
视频截图
MyFile.genVideoSnapshot(params)
params参数说明
| 参数 | 类型 | 必填 | 说明 | | :----- | :-- -- | :-- | :-- | | source | String | Y | 视频文件的 id | | save_as | String | Y | 截图保存的文件名 | | point | String | Y | 截图时间格式,格式:HH:MM:SS | | category_id | String | N | 文件所属类别 ID | | random_file_link | Boolean | N | 是否使用随机字符串作为文件的下载地址,不随机可能会覆盖之前的文件,默认为 true | | size | String | N | 截图尺寸,格式为 宽 x 高,默认是视频尺寸 | | format | String | N | 截图格式,可选值为 jpg,png, webp, 默认根据 save_as 的后缀生成 |
返回参数说明
res.data:
参数 | 类型 | 说明 |
---|---|---|
created_at | Integer | 创建时间 (格式为 unix 时间戳) |
path | String | 上传成功后的访问地址 URL |
created_by | Integer | 创建者 id |
mime_type | String | mime_type 类型 |
media_type | String | 媒体类型 |
size | Integer | 文件大小 |
name | String | 文件名 |
status | String | 文件状态 |
reference | String | 引用 |
cdn_path | String | 文件在 CDN 中的相对路径 |
updated_at | Integer | 更新时间 (格式为 unix 时间戳) |
categories | String | 文件所属类别 |
id | String | 本条记录 ID |
示例代码
HError 对象结构请参考错误码和 HError 对象
返回示例
M3U8 视频拼接
MyFile.videoConcat(params)
params参数说明
| 参数 | 类型 | 必填 | 说明 | | :----- | :-- -- | :-- | :-- | | m3u8s | Array | Y | 视频文件的 id 列表,按提交的顺序进行拼接 | | save_as | String | Y | 截图保存的文件名 | | category_id | String | N | 文件所属类别 ID | | random_file_link | Boolean | N | 是否使用随机字符串作为文件的下载地址,不随机可能会覆盖之前的文件,默认为 true |
返回参数说明
res.data:
参数 | 类型 | 说明 |
---|---|---|
created_at | Integer | 创建时间 (格式为 unix 时间戳) |
path | String | 上传成功后的访问地址 URL |
created_by | Integer | 创建者 id |
mime_type | String | mime_type 类型 |
media_type | String | 媒体类型 |
size | Integer | 文件大小 |
name | String | 文件名 |
status | String | 文件状态 |
reference | String | 引用 |
cdn_path | String | 文件在 CDN 中的相对路径 |
updated_at | Integer | 更新时间 (格式为 unix 时间戳) |
categories | String | 文件所属类别 |
_id | String | 本条记录 ID |
示例代码
HError 对象结构请参考错误码和 HError 对象
返回示例
M3U8 视频剪辑
MyFile.videoClip(params)
params参数说明
| 参数 | 类型 | 必填 | 说明 | | :----- | :-- -- | :-- | :-- | | m3u8 | String | Y | 视频文件的 id | | save_as | String | Y | 截图保存的文件名 | | category_id | String | N | 文件所属类别 ID | | random_file_link | Boolean | N | 是否使用随机字符串作为文件的下载地址,不随机可能会覆盖之前的文件,默认为 true | | include | Array | N | 包含某段内容的开始结束时间,单位是秒。当 index 为 false 时,为开始结束分片序号 | | exclude | Array | N | 不包含某段内容的开始结束时间,单位是秒。当 index 为 false 时,为开始结束分片序号 | | index | Boolean | N | include 或者 exclude 中的值是否为 ts 分片序号,默认为 false |
返回参数说明
res.data:
参数 | 类型 | 说明 |
---|---|---|
created_at | Integer | 创建时间 (格式为 unix 时间戳) |
path | String | 上传成功后的访问地址 URL |
created_by | Integer | 创建者 id |
mime_type | String | mime_type 类型 |
media_type | String | 媒体类型 |
size | Integer | 文件大小 |
name | String | 文件名 |
status | String | 文件状态 |
reference | String | 引用 |
cdn_path | String | 文件在 CDN 中的相对路径 |
updated_at | Integer | 更新时间 (格式为 unix 时间戳) |
categories | String | 文件所属类别 |
_id | String | 本条记录 ID |
示例代码
HError 对象结构请参考错误码和 HError 对象
返回示例
M3U8 时长和分片信息
MyFile.videoMeta(params)
params参数说明
| 参数 | 类型 | 必填 | 说明 | | :----- | :-- -- | :-- | :-- | | m3u8 | String | Y | 视频文件的 id |
返回参数说明
res.data:
参数 | 类型 | 说明 |
---|---|---|
status_code | Integer | 状态码 |
message | String | 返回信息 |
meta | Object | 详见以下 |
meta 参数说明:
参数 | 类型 | 说明 |
---|---|---|
duartion | Number | m3u8 时长 |
points | Array | 时间点 |
示例代码
HError 对象结构请参考错误码和 HError 对象
返回示例
音视频的元信息
MyFile.videoAudioMeta(params)
params参数说明
| 参数 | 类型 | 必填 | 说明 | | :----- | :-- -- | :-- | :-- | | source | String | Y | 文件的 id |
返回参数说明
res.data:
参数 | 类型 | 说明 |
---|---|---|
format | Object | 音视频格式信息,详见以下 |
streams | Array | stream 列表,详见以下 |
format 参数说明:
参数 | 类型 | 说明 |
---|---|---|
bitrate | Integer | 比特率 |
duration | Number | 时长 |
format | String | 容器格式 |
fullname | String | 容器格式全称 |
streams 参数说明:
参数 | 类型 | 说明 |
---|---|---|
index | Integer | 表示第几路流 |
type | String | 一般情况下, video 或 audio |
bitrate | Integer | 流码率 |
codec | String | 流编码 |
codec_desc | String | 流编码说明 |
duration | Number | 流时长 |
video_fps | Number | (视频流)视频帧数 |
video_height | Integer | (视频流)视频高度 |
video_width | Integer | (视频流)视频宽度 |
audio_channels | Integer | (音频流)音频通道数 |
audio_samplerate | Integer | (音频流)音频采样率 |
示例代码
HError 对象结构请参考错误码和 HError 对象
返回示例
刷新 CDN 缓存
MyFile.purgeCache(operationType, content)
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
operationType | String | Y | 操作类型,包括: |
content | Array | Y | 操作的 URL 列表 |
示例代码
HError 对象结构请参考错误码和 HError 对象
返回示例
获取 CDN 缓存刷新操作记录
MyFile.getPurgeCacheHistory(params)
params 参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
params.limit | Number | N | 数量限制 |
params.offset | Number | N | 偏移量 |
params.operationType | String | N | 操作类型,包括: |
params.created_at__gte | Number | N | 创建时间区间的开始时间(时间戳) |
params.created_at__lte | Number | N | 创建时间区间的结束时间(时间戳) |
示例代码
HError 对象结构请参考错误码和 HError 对象
返回示例
Last updated