@charbo/ufile-node-sdk

1.3.3 • Public • Published

ufile-node-sdk

ufile官方的Node SDK改进

(分片上传及bucket操作暂未实现,请勿使用)

接口参数和返回参考https://docs.ucloud.cn/api/ufile-api/index

API配置:在根目录创建 ufile-config.json或直接在初始化时传值

UFile

Kind: global class

new UFile(publicKey, privateKey, bucket, domain, protocol)

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配置参数

uFile.getPrefixFileList(prefix, marker, limit) ⇒ Promise

前缀列表查询

Kind: instance method of UFile

Param Type Description
prefix string 前缀,utf-8编码
marker string 标志字符串,utf-8编码
limit number 文件列表数目,默认为20

uFile.uploadHit(key, filePath, prefix, fileRename, unique) ⇒ Object

秒传文件

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

uFile.putFile(key, filePath, prefix, fileRename, unique) ⇒ Object

上传文件

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

uFile.getFile(key) ⇒ Object

下载文件

Kind: instance method of UFile
Returns: Object - 状态码及文件保存路径

Param Type Description
key string key

uFile.transferFile(urlArr) ⇒ Array

文件转移

Kind: instance method of UFile
Returns: Array - 转移后的资源路径

Param Type Description
urlArr Array 源文件链接数组,数组元素可为字符串或对象

uFile.headFile(key) ⇒ Object

查询文件基本信息

Kind: instance method of UFile
Returns: Object - API响应头

Param Type
key string

uFile.deleteFile(key) ⇒ Object

删除文件

Kind: instance method of UFile
Returns: Object - 状态码和状态信息

Param Type
key string

uFile._sendRequest(url, method, headers, key, query, body) ⇒ request | Promise

发送请求

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 请求体

uFile._sign(method, headers, bucket, key, body) ⇒ request | Promise

生成签名

Kind: instance method of UFile
Returns: request | Promise - 状态码和状态信息

Param Type Description
method string 请求方法
headers string 请求头
bucket string 资源bucket
key string 请求key
body string 请求体

uFile.initiateMultipartUpload(key) ⇒ Promise

初始化分片上传

Kind: instance method of UFile

Param Type Description
key string 文件名

uFile.uploadPart(key, uploadId, partNumber, buffer) ⇒ Promise

上传分片

Kind: instance method of UFile

Param Type Description
key string 文件名
uploadId string 分片id
partNumber number 第几块分片
buffer buffer 内容

uFile.finishMultipartUpload(key, uploadId, [newKey], parts) ⇒ Promise

完成分片

Kind: instance method of UFile

Param Type Description
key string 文件名
uploadId string 分片id
[newKey] string 等上传完毕开始指定的key可能已经被占用,遇到这种情形时会采用newKey参数的值作为文件最终的key,否则仍然采用原来的key
parts array 分片的etag们

uFile.abortMultipartUpload(key, uploadId) ⇒ Promise

放弃分片

Kind: instance method of UFile

Param Type Description
key string 文件名
uploadId string 分片id

uFile.getMultiUploadId([prefix], [marker], [limit]) ⇒ Promise

获取正在执行的分片上传

Kind: instance method of UFile

Param Type Default Description
[prefix] string 前缀,utf-8编码,默认为空字符串
[marker] string 标志字符串,utf-8编码,默认为空字符串
[limit] number 20 id列表数目,默认为20

uFile.getMultiUploadPart(uploadId) ⇒ Promise

获取已上传成功的分片列表

Kind: instance method of UFile

Param Type Description
uploadId string 上传id

uFile.opMeta(key, mimeType) ⇒ Promise

操作文件的Meta信息

Kind: instance method of UFile

Param Type Description
key string key
mimeType string 文件的mimetype

Readme

Keywords

Package Sidebar

Install

npm i @charbo/ufile-node-sdk

Weekly Downloads

1

Version

1.3.3

License

MIT

Unpacked Size

39 kB

Total Files

6

Last publish

Collaborators

  • charbo