ufile官方的Node SDK改进
(分片上传及bucket操作暂未实现,请勿使用)
接口参数和返回参考https://docs.ucloud.cn/api/ufile-api/index
API配置:在根目录创建 ufile-config.json或直接在初始化时传值
Kind: global class
- UFile
- new UFile(publicKey, privateKey, bucket, domain, protocol)
- .setProps(props) ⇒
UFile - .getPrefixFileList(prefix, marker, limit) ⇒
Promise - .uploadHit(key, filePath, prefix, fileRename, unique) ⇒
Object - .putFile(key, filePath, prefix, fileRename, unique) ⇒
Object - .getFile(key) ⇒
Object - .transferFile(urlArr) ⇒
Array - .headFile(key) ⇒
Object - .deleteFile(key) ⇒
Object - ._sendRequest(url, method, headers, key, query, body) ⇒
request|Promise - ._sign(method, headers, bucket, key, body) ⇒
request|Promise - .initiateMultipartUpload(key) ⇒
Promise - .uploadPart(key, uploadId, partNumber, buffer) ⇒
Promise - .finishMultipartUpload(key, uploadId, [newKey], parts) ⇒
Promise - .abortMultipartUpload(key, uploadId) ⇒
Promise - .getMultiUploadId([prefix], [marker], [limit]) ⇒
Promise - .getMultiUploadPart(uploadId) ⇒
Promise - .opMeta(key, mimeType) ⇒
Promise
UFile SDK
| Param | Type | Description |
|---|---|---|
| publicKey | string |
api公钥 |
| privateKey | string |
api私钥 |
| bucket | string |
存储空间名 |
| domain | string |
存储空间域名 |
| protocol | boolean |
网络协议头 |
uFile.setProps(props) ⇒ UFile
返回一个修改部分参数的UFile对象
Kind: instance method of UFile
Returns: UFile - 新的UFile对象
| Param | Type | Description |
|---|---|---|
| props | Object |
ufile配置参数 |
前缀列表查询
Kind: instance method of UFile
| Param | Type | Description |
|---|---|---|
| prefix | string |
前缀,utf-8编码 |
| marker | string |
标志字符串,utf-8编码 |
| limit | number |
文件列表数目,默认为20 |
秒传文件
Kind: instance method of UFile
Returns: Object - 状态码及上传成功的资源路径
| Param | Type | Description |
|---|---|---|
| key | string |
文件key,会屏蔽prefix和fileRename |
| filePath | string |
待上传文件的路径 |
| prefix | string |
文件前缀 |
| fileRename | string |
重命名文件名(若无后缀会自动加上后缀) |
| unique | Boolean | string | Number |
是否唯一,若传入ture则自动生成id,若传入Number或string则将其作为id |
上传文件
Kind: instance method of UFile
Returns: Object - 状态码及上传成功的资源路径
| Param | Type | Description |
|---|---|---|
| key | string |
文件key,会屏蔽prefix和fileRename |
| filePath | string |
待上传文件的路径 |
| prefix | string |
文件前缀 |
| fileRename | string |
重命名文件名(若无后缀会自动加上后缀) |
| unique | Boolean | string | Number |
是否唯一,若传入ture则自动生成id,若传入Number或string则将其作为id |
下载文件
Kind: instance method of UFile
Returns: Object - 状态码及文件保存路径
| Param | Type | Description |
|---|---|---|
| key | string |
key |
文件转移
Kind: instance method of UFile
Returns: Array - 转移后的资源路径
| Param | Type | Description |
|---|---|---|
| urlArr | Array |
源文件链接数组,数组元素可为字符串或对象 |
查询文件基本信息
Kind: instance method of UFile
Returns: Object - API响应头
| Param | Type |
|---|---|
| key | string |
删除文件
Kind: instance method of UFile
Returns: Object - 状态码和状态信息
| Param | Type |
|---|---|
| key | string |
发送请求
Kind: instance method of UFile
Returns: request | Promise - 状态码和状态信息
| Param | Type | Description |
|---|---|---|
| url | string |
请求的url,会屏蔽key |
| method | string |
请求方法 |
| headers | string |
请求头 |
| key | string |
请求key |
| query | string |
查询参数 |
| body | string |
请求体 |
生成签名
Kind: instance method of UFile
Returns: request | Promise - 状态码和状态信息
| Param | Type | Description |
|---|---|---|
| method | string |
请求方法 |
| headers | string |
请求头 |
| bucket | string |
资源bucket |
| key | string |
请求key |
| body | string |
请求体 |
初始化分片上传
Kind: instance method of UFile
| Param | Type | Description |
|---|---|---|
| key | string |
文件名 |
上传分片
Kind: instance method of UFile
| Param | Type | Description |
|---|---|---|
| key | string |
文件名 |
| uploadId | string |
分片id |
| partNumber | number |
第几块分片 |
| buffer | buffer |
内容 |
完成分片
Kind: instance method of UFile
| Param | Type | Description |
|---|---|---|
| key | string |
文件名 |
| uploadId | string |
分片id |
| [newKey] | string |
等上传完毕开始指定的key可能已经被占用,遇到这种情形时会采用newKey参数的值作为文件最终的key,否则仍然采用原来的key |
| parts | array |
分片的etag们 |
放弃分片
Kind: instance method of UFile
| Param | Type | Description |
|---|---|---|
| key | string |
文件名 |
| uploadId | string |
分片id |
获取正在执行的分片上传
Kind: instance method of UFile
| Param | Type | Default | Description |
|---|---|---|---|
| [prefix] | string |
前缀,utf-8编码,默认为空字符串 | |
| [marker] | string |
标志字符串,utf-8编码,默认为空字符串 | |
| [limit] | number |
20 |
id列表数目,默认为20 |
获取已上传成功的分片列表
Kind: instance method of UFile
| Param | Type | Description |
|---|---|---|
| uploadId | string |
上传id |
操作文件的Meta信息
Kind: instance method of UFile
| Param | Type | Description |
|---|---|---|
| key | string |
key |
| mimeType | string |
文件的mimetype |