jss-sdk-node v2.0.5
Classes
jss介绍
http://jpcloud.jd.com/display/cloud/JSS
http://jpcloud.jd.com/pages/viewpage.action?pageId=10658955
raw rest api
详见文档 http://storage.jd.com/jss/jss-http-api.pdf
Jss
Jss 类型 代表着 Jingdong Storage Service 客户端
Kind: global class
- Jss
- new Jss(endpoint, accessKey, secretKey, useHttps, presignUrl, logger, umpProfiler, umpKeyPrefix)
- .bucket(bucketName) ⇒ Bucket
- .listBucket() ⇒ Promise.<Array.<bucket>>
- .hasBucket() ⇒ Promise.<boolean> | Promise.<Error>
new Jss(endpoint, accessKey, secretKey, useHttps, presignUrl, logger, umpProfiler, umpKeyPrefix)
创建一个 Jss 客户端实例
Param | Type | Required | Description |
---|---|---|---|
endpoint | string | 必填 | 所要连接的 endpoint 地址 |
accessKey | string | 必填 | 字符串 accessKey |
secretKey | string | 必填 | 字符串 secretKey |
useHttps | string | 必填 | 是否使用 https |
presignUrl | string | 必填 | 预签名host |
logger | string | 选填 | 统一日志平台(logbook)接入客户端 (@jd/jmfe-node-logbook), 用于日志记录 |
umpProfiler | string | 选填 | 统一监控平台(ump)客户端实例 (@jd/node-ump-sdk), 用于 jss 操作方法的 ump 监控接入 |
umpKeyPrefix | string | 选填 | 接入统一日志平台时的 key 前缀, key 的命名请参考 ump 平台, 注意不要与 ump 平台其它 key 冲突,默认Jss |
Example
const Ump = require('@jd/node-ump-sdk');
const ump = new Ump({
nodeAppName: 'JssTest',
logPath: '/your/log/path/',
nodeAppInstance: '0'
});
const Logbook = require('@jd/jmfe-node-logbook');
const logbook = new Logbook({
nodeAppName: 'JssTest',
logPath: '/your/log/path/'
});
const logger = logbook.getLogger();
const profiler = ump.getProfiler();
const jss=new Jss('storage.jd.com','your-accessKey-here','your-secretKey-here',true,'storage.jd.com', logger, profiler, 'xx.jd.com');
jss.bucket(bucketName) ⇒ Bucket
新建一个 Bucket 对象 该对象封装了对 Bucket 的操作
Kind: instance method of Jss
Returns: Bucket - 新建的 Bucket 对象
Access: public
Param | Type | Description |
---|---|---|
bucketName | string | bucket的名字; |
Example
var bucket=jss.bucket('bucket-name');
jss.listBucket() ⇒ Promise.<Array.<bucket>>
列出所有 bucket
Kind: instance method of Jss
Access: public
Example
jss.listBucket().then(function (res) {
console.log(res)
}).catch(function (err) {
console.log(err)
})
jss.hasBucket() ⇒ Promise.<boolean> | Promise.<Error>
是否拥有指定名字的 bucket
Kind: instance method of Jss
Returns: Promise.<boolean> - resolve,拥有则为 true,否则为 falsePromise.<Error> - reject,失败时为错误对象
Access: public
Example
jss.listBucket().then(function (res) {
console.log(res)
}).catch(function (err) {
console.log(err)
})
Acl
权限控制类 Access Control List
设置、删除 bucket 的访问权限
被授权人由其 accessKey 标识; 权限分为 READ
WRITE
FULL_CONTROL
三种; 权限控制粒度为 bucket 层次,不能对单个资源 (Object)权限控制
由于缓存的作用,更新/删除Bucket-Acl操作至多需要1分钟才能全局生效。
Kind: global class
- Acl
- new Acl(bucket, client)
- .allowAnyoneRead() ⇒ Acl
- .internetVisible(isVisible) ⇒ Acl
- .grant(grantee, permission) ⇒ Acl
- .grants(grants) ⇒ Acl
- .set() ⇒ Promise.<Response.body> | Promise.<Error>
- .delete() ⇒ Promise.<Response.body> | Promise.<Error>
- .get() ⇒ Promise.<Response.body> | Promise.<Error>
new Acl(bucket, client)
创建一个 Acl 实例
Param | Type | Description |
---|---|---|
bucket | Bucket | Acl 所属的 Bucket 实例 |
client | Client | Client 实例 |
acl.allowAnyoneRead() ⇒ Acl
允许任何人可读 此方法仅起配置作用,请调用 set() 方法使配置生效
Kind: instance method of Acl
Returns: Acl - 返回 Acl 对象
Access: public
Example
jss.bucket('pro-test').acl().internetVisible(true).allowAnyoneRead().set().then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
acl.internetVisible(isVisible) ⇒ Acl
网络可见 即 Bucket 允许互联网上任何人匿名访问 此方法仅起配置作用,请调用 set() 方法使配置生效
Kind: instance method of Acl
Returns: Acl - 返回 Acl 对象
Access: public
Param | Type | Description |
---|---|---|
isVisible | boolean | 是否可见,可见则为 true,不可见为 false |
Example
jss.bucket('pro-test').acl().internetVisible(true).allowAnyoneRead().set().then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
acl.grant(grantee, permission) ⇒ Acl
增加一个权限设置 即 Bucket 允许互联网上任何人匿名访问 此方法仅起配置作用,请调用 set() 方法使配置生效
Kind: instance method of Acl
Returns: Acl - 返回 Acl 对象
Access: public
Param | Type | Description |
---|---|---|
grantee | string | 被授权人的 accessKey |
permission | string | 被授予的权限 |
Example
jss.bucket('pro-test').acl().internetVisible(true).grant('*','READ').set().then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
acl.grants(grants) ⇒ Acl
增加权限设置列表 此方法仅起配置作用,请调用 set() 方法使配置生效
Kind: instance method of Acl
Returns: Acl - 返回 Acl 对象
Access: public
Param | Type | Description |
---|---|---|
grants | Array.<Object> | 是一个由配置对象组成的数组,每个配置对象构成如下: {Grantee: 'grantee accesskey here', Permission: 'permission string'} |
Example
jss.bucket('pro-test').acl().internetVisible(true).grants([{Grantee:'accesskey one',Permission:'READ'},{Grantee:'accesskey two',Permission:'READ'}]).set().then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
acl.set() ⇒ Promise.<Response.body> | Promise.<Error>
配置权限 使配置生效
Kind: instance method of Acl
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的Body为空; Promise.<Error> - reject,失败时为错误对象
Access: public
Example
jss.bucket('pro-test').acl().internetVisible(true).allowAnyoneRead().set().then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
acl.delete() ⇒ Promise.<Response.body> | Promise.<Error>
删除权限配置 该 bucket 下所有的权限配置都会被删除,调用此方法后立即执行
Kind: instance method of Acl
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的Body为空; Promise.<Error> - reject,失败时为错误对象
Access: public
Example
jss.bucket('pro-test').acl().delete().then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
acl.get() ⇒ Promise.<Response.body> | Promise.<Error>
获取权限配置 获取 bucket 下所有已配置的权限信息
Kind: instance method of Acl
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的 Body 格式如下:
{
"Bucket":"pro-test", // Bucket 名称
"CreationDate":"Mon, 18 Sep 2017 14:47:59 GMT", // Bucket 创建时间
"AccessControlList":[{"Grantee":"*","Permission":"READ"}], // 权限控制数组
"Referer":null, // Referer
"InternetVisible":true // 是否网络可见
}
Promise.<Error> - reject,失败时为错误对象
Access: public
Example
jss.bucket('pro-test').acl().get().then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
Bucket
Bucket 类型 Bucket是存放“文件”(云存储称之为Object)的容器,所有的Object都必须存放到某个Bucket中。
Kind: global class
- Bucket
- new Bucket(name, client)
- .create() ⇒ Promise.<Response.body> | Promise.<Error>
- .delete() ⇒ Promise.<Response.body> | Promise.<Error>
- .object(key) ⇒ JssObject
- .acl() ⇒ Acl
- .listObject(marker, maxKeys, prefix, delimiter) ⇒ Promise.<Response.body> | Promise.<Error>
new Bucket(name, client)
创建一个 Bucket 实例
Param | Type | Description |
---|---|---|
name | string | Bucket 名称 |
client | Client | Client 实例 |
bucket.create() ⇒ Promise.<Response.body> | Promise.<Error>
新建一个 Bucket 每个用户最多可以创建 100个Bucket,每个 Bucket 中可以存放无限多个 Object。Bucket 不能嵌套。 Bucket 的名称全局唯一且严格的限制,包括: 1. 仅包含小写英文字母(a-z),数字,点(.)和横线(-) 2. 必须由字母或数字开头和结尾 3. 长度在 3 和 63 个字符之间 4. 不能为IP地址形式,比如192.168.1.1 5. 不能包含连续的点(.)与横线(-)组合
Kind: instance method of Bucket
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的Body为空; Promise.<Error> - reject,失败是为错误对象
Access: public
Example
var bkt=jss.bucket('test-bucket');
bkt.create().then((res)=>{
console.log('新建 bucket 成功');
}.catch((err)=>{
console.log('新建 bucket 失败:'+err.message);
})
bucket.delete() ⇒ Promise.<Response.body> | Promise.<Error>
删除一个 Bucket
Kind: instance method of Bucket
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 204, 返回的Body为空; Promise.<Error> - reject,失败时为错误对象
Access: public
Example
var bkt=jss.bucket('test-bucket');
bkt.delete().then((res)=>{
console.log('删除 bucket 成功');
}.catch((err)=>{
console.log('删除 bucket 失败:'+err.message);
})
bucket.object(key) ⇒ JssObject
创建一个 JssObject
Kind: instance method of Bucket
Returns: JssObject - 新建的 JssObject 对象
Access: public
Param | Type | Description |
---|---|---|
key | string | Object的名字; |
Example
var object=jss.bucket('bucket-name').object('object-name')
bucket.acl() ⇒ Acl
创建一个 acl 对象
Kind: instance method of Bucket
Returns: Acl - 新建的 acl 对象
Access: public
Example
var acl=jss.bucket('bucket-name').acl()
bucket.listObject(marker, maxKeys, prefix, delimiter) ⇒ Promise.<Response.body> | Promise.<Error>
列出 指定Bucket中的Object信息列表 请求时可以通过一些查询条件来限制返回的结果。
Kind: instance method of Bucket
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的 Body 为 json 格式,包含以下字段:
字段 | 含义 |
---|---|
Name | Bucket的名称 |
Delimiter | 指定的Delimiter分组符 |
Prefix | 指定的Object Key的前缀 |
MaxKeys | 指定的Object的数量 |
Marker | 指定的Object的Key的起始标志 |
NextMarker | 列出下一个集合的Marker,只有当用户设置了delimiter 且 HasNext为true时才会出现,其值可能是当前集合中最后一个Key,或是CommonPrefixes中最后一个Prefix, 若用户没有设置delimiter,且HasNext为true时,可以直接将返回集合中的最后一个Key作为列出下一个结合的Marker |
HasNext | 标识返回的结果是否完整 (true or false),若符合条件的Object 信息数量超过了指定的MaxKeys,则该值为true,且多余的结果也不会被返回。 |
Contents | 包含了一个Object信息的容器 |
Key | Object的Key |
LastModified | Object的最后修改时间 |
ETag | Object的ETag是一个MD5 hash值,其只反映Object内容的变化,而不是元数据(Metadata) |
Size | Object的大小 |
CommonPrefixes | 用户指定了Delimiter时,该元素才会出现。用于存放分组后Object Key前缀。 |
{ Name: 'pro-test',
Prefix: null,
Marker: null,
Delimiter: null,
MaxKeys: 2,
HasNext: true,
Contents:
[ { Key: 'pro-a.txt',
LastModified: 'Mon, 11 Sep 2017 17:47:04 GMT',
ETag: '0cc175b9c0f1b6a831c399e269772661',
Size: 1 },
{ Key: 'pro-b.txt',
LastModified: 'Mon, 11 Sep 2017 17:47:15 GMT',
ETag: '92eb5ffee6ae2fec3ad71c777531578f',
Size: 1 } ],
CommonPrefixes: null }
Promise.<Error> - reject,失败是为错误对象 Access: public
Param | Type | Description |
---|---|---|
marker | string | 返回以字典序排序的 Object 信息的起始标志,结果中不包含marker,通常与max-keys一起使用来实现分页 |
maxKeys | integer | 返回Object信息的数量,最大为1000,若有更多符合查询条件的Object信息没有被返回,则响应中会包含HasNext为true元素,同时可以设定marker为本次列表最后一个Key,来获取其他的本次操作未返回的Object信息。默认为1000 |
prefix | integer | 限制返回Object的Key的前缀 |
delimiter | integer | 分组符,用于分组返回的Object的Key。当prefix未指定时,从Object的Key中提取第一个字符到第一个delimiter之间的字符串放在CommonPrefixes中返回。若指定了prefix,则提取prefix到第一个delimiter之间的字符串放在CommonPrefixes中返回 |
Example
jss.bucket('pro-test').listObject(undefined, 2, '', undefined).then((res)=> {
console.log(res);
if (res.HasNext) {
var marker = res.Contents[res.Contents.length - 1].Key;
jss.bucket('pro-test').listObject(marker, 1000).then((res)=> {
console.log(res)
}).catch((err)=> {
console.log('listObject 2 失败:' + err.message);
})
}
}).catch((err)=> {
console.log('listObject 1 失败:' + err.message);
})
JssObject
JssObject 类型 Object 是京东云存储中的基本实体,由键(Key),数据(Data)和元数据(Metadata)三部分组成。关于数据(Data),京东云存储并不关心其内容具体是什么。而元数据(Metadata)则是一组键值(Key-Value)的组合,包括数据的长度,创建时间,MD5 值等。
Kind: global class
- JssObject
- new JssObject(key, bucket, client)
- .get() ⇒ Promise.<Response.body> | Promise.<Error>
- .put(path) ⇒ Promise.<Response.body> | Promise.<Error>
- .saveToFile(options)
- .head() ⇒ Promise.<Response.body> | Promise.<Error>
- .exist() ⇒ Promise.<Error>
- .delete() ⇒ Promise.<Error>
new JssObject(key, bucket, client)
创建一个 JssObject 实例
Param | Type | Description |
---|---|---|
key | string | Object 的 key Key 是一个 Object 的标识,在每一个 Bucket 中,每个 Object 有且仅有一个 Key。而用户可以通过 Bucket + Key 的方式唯一标识云存储中的一个 Object,例如对于 URL:http://storage.jcloud.com/mybucket/public/index.html域名之后到第一个斜线(/)是 Bucket,为 mybucket,之后是 Object 的 Key,为public/index.html |
bucket | Bucket | Object 所属的 Bucket 实例 |
client | Client | Client 实例 |
jssObject.get() ⇒ Promise.<Response.body> | Promise.<Error>
下载一个资源并读取其内容
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, resolve 获得文件内容 Promise.<Error> - reject,失败时为错误对象; 例如资源不存在时 statusCode 为 404,消息为 {"code":"NoSuchKey","message":"The specified key does not exist.","resource":"/protest/test.html","requestId":"90517BDD0F94D467"}
Access: public
Example
jss.bucket('pro-test').object('test.html').get()
.then(function (res) {
console.log(res) // 这里输出的是文件内容
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
jssObject.put(path, fileName) ⇒ Promise.<Response.body> | Promise.<Error>
上传或替换一个资源
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的Body为空; Promise.<Error> - reject,失败时为错误对象
Access: public
Param | Type | Description | Require |
---|---|---|---|
path | string | 要上传资源的本地路径 | Y |
fileName | string | 下载文件的时候,保存的文件名称,如果设置的话,会提醒浏览器下载文件(如果不需要浏览器提醒下载,请不要设置) | N |
Example
jss.bucket('pro-test').object('test.html').put('/file/path/test.html', 'fileName.html')
.then(function (res) {
console.log('上传资源成功')
console.log(res) // { md5: '25e2d38c4b2575363a693798064cca15' } 文件的md5值
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
jssObject.saveToFile(options)
下载资源并保存到本地 提供流式文件下载,以及下载进度回调
Kind: instance method of JssObject
Access: public
Param | Type | Description |
---|---|---|
options | Object | 入参字段及含义如下: |
options.targetPath | Object | 要保存的目标路径 |
options.finishCb | Object | 任务完成回调; function(error, transferredLength){} 第一个参数为 error,如果不为空,说明出错啦; 第二个参数是下载完成的内容大小,单位为字节 |
options.progressCb | Object | 下载进度回调; function(progressInfo){} , progressInfo 是一个对象,字段及其含义如下: transferred,表示已经下载的大小; contentLength,表示文件的总大小,单位为字节; percentage,下载完成的百分比; runtime,已经消耗的时间; speed,下载速度单位为 byte/s |
options.throttleInterval | Object | 下载进度回调的触发节流,需设置为 必须大于 0 并小于 10000 的整数,若不设置,默认 100 毫秒触发一次 |
Example
jss.bucket('pro-test').object('object-name-here').saveToFile({
targetPath: '/your/target/path/here',
finishCb: function (err, contentLength) {
if (err) {
console.log(err.message);
return;
}
console.log('文件下载完成,体积:' + (contentLength / 1024) + ' kb');
},
progressCb: function (progress) {
console.log(progress);
},
throttleInterval: 200
});
jssObject.head() ⇒ Promise.<Response.body> | Promise.<Error>
获取资源的元数据
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, resolve 的内容为元数据,形如:
{
'server': 'JDWS/1.0.0',
'date': 'Fri, 15 Sep 2017 08:59:50 GMT',
'content-type': 'text/plain',
'content-length': '0',
'connection': 'close',
'x-jss-request-id': 'B5E4E800DEF0CA13',
'content-disposition': 'attachment; filename="pro-a.txt"',
'accept-ranges': 'bytes',
'etag': "0cc175b9c0f1b6a831c399e269772661",
'last-modified': 'Mon, 11 Sep 2017 17:47:04 GMT',
'expires': 'Fri, 15 Sep 2017 08:59:50 GMT',
'cache-control': 'max-age=0'
}
Promise.<Error> - reject,失败时为错误对象;
Access: public
Example
jss.bucket('pro-test').object('pro-a.txt').head().then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
jssObject.exist() ⇒ Promise.<Error>
判断某个资源是否存在
Kind: instance method of JssObject
Returns: Promise.<Error> - reject,失败时为错误对象;
Access: public
Example
jss.bucket('pro-test').object('pro-a.txt').update({fileName: 'test.txt'}).then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
jssObject.delete() ⇒ Promise.<Error>
删除资源
Kind: instance method of JssObject
Returns: Promise.<Error> - reject,失败时为错误对象;
Access: public
Example
jss.bucket('pro-test').object('pro-a.txt').delete().then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
在
http://npm.m.jd.com/package/@jd/jmfe-node-jss
这个库的基础增加下面几个方法
jssObject.putStream(stream, md5Value, fileName) ⇒ Promise.<Response.body> | Promise.<Error>
上传一个Stream
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的Body为空; Promise.<Error> - reject,失败时为错误对象
Access: public
Param | Type | Description | Require |
---|---|---|---|
stream | stream | 要上传的文件流 | Y |
md5Value | Sting | 文件的md5值 | Y |
fileName | Sting | 下载时文件的保存名,如果设置的话,会提醒浏览器下载文件(如果不需要浏览器提醒下载,请不要设置) | N |
说明
适合从客户端直接上传到服务器,服务器直接转流到jss
Example
jss.bucket('pro-test').object('test.html').putStream(stream, md5Value, fileName)
.then(function (res) {
console.log('上传资源成功')
console.log(res) // { md5: '25e2d38c4b2575363a693798064cca15' } 文件的md5值
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
jssObject.update({fileName: 'test.jpg'}) ⇒ Promise.<Response.body> | Promise.<Error>
更新资源的元数据(目前只支持更新content-disposition)
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, resolve形如:
{
LastModified:"Wed, 28 Feb 2018 09:36:02 GMT",
Etag:"562eb1935caaa04615f508f4660206ae"
}
Access: public
Param | Type | Description | Require |
---|---|---|---|
metaInfo | Object | {fileName: 'test.jpg'} | Y |
Example
jss.bucket('pro-test').object('pro-a.txt').update({fileName: 'test.jpg'}).then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
生成文件预下载地址
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, resolve形如:
http://test.storage.jd.com/resoucearea/b1ad0786-eb52-49f9-b962-cc839c036ed7.jpg?Expires=1519893073&AccessKey=iZapekcFlBHrbbPc&Signature=%2FWv%2F7LPHjqKoVs06S4WztMwz904%3D
Access: public
Param | Type | Description | Require |
---|---|---|---|
expireTime | Intger | 失效时间 单位毫秒数 | Y |
localPresignUrl | String | 自定义下载host | N |
Example
jss.bucket('pro-test').object('pro-a.txt').makeDownLoadUrl(1000);
生成文件预上传地址
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, resolve形如:
http://test.storage.jd.com/resoucearea/b1ad0786-eb52-49f9-b962-cc839c036ed7.jpg?Expires=1519893073&AccessKey=iZapekcFlBHrbbPc&Signature=%2FWv%2F7LPHjqKoVs06S4WztMwz904%3D
Access: public
Param | Type | Description | Require |
---|---|---|---|
expireTime | Intger | 失效时间 单位毫秒数 | Y |
fileName | Intger | 失效时间 单位毫秒数 | Y |
contentType | Intger | 失效时间 单位毫秒数 | Y |
localPresignUrl | String | 自定义上传host | N |
Example
jss.bucket('pro-test').object('pro-a.txt').makeUploadFileUrl(1000);
jssObject.initMultipartUpload() ⇒ Promise.<Response.body> | Promise.<Error>
文件分块上传初始化请求
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的Body为空; Promise.<Error> - reject,失败时为错误对象
{
"Bucket":"liningbo",
"Key":"testObject",
"UploadId":"1e34f32a9d1c40ccab504b3c39074dcc"
}
Access: public
Example
jss.bucket('protest').object('multi.txt').initMultipartUpload()
.then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
jssObject.uploadPart(uploadId, partNumber, inputStream) ⇒ Promise.<Response.body> | Promise.<Error>
文件分块上传 上传分块
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的Body为空; Promise.<Error> - reject,失败时为错误对象
{
ETag: '562eb1935caaa04615f508f4660206ae',
PartNumber: 1
}
Access: public | Param | Type | Description | Require | | --- | --- | --- | --- | | uploadId | String | 分块上传初始化返回的uploadId | Y | | partNumber | String | 当前块编号从1开始 | Y | | inputStream | String | 分块文件流 | Y |
Example
jss.bucket(bucketName).object(objectKey).uploadPart(uploadId, chunk, stream)
.then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
jssObject.completeMultipartUpload(uploadId, parts) ⇒ Promise.<Response.body> | Promise.<Error>
文件分块上传 完成分块上传
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的Body为空; Promise.<Error> - reject,失败时为错误对象
{
"Bucket":"liningbo",
"Key":"testObject",
"ETag":"d25ebb012cdbb28a3f309ea565c56cea"
}
Access: public | Param | Type | Description | Require | | --- | --- | --- | --- | | uploadId | String | 分块上传初始化返回的uploadId | Y | | parts | String | 分块数组,每个对象的结构 {PartNumber: 1, ETag: 'ETag'} | Y |
Example
jss.bucket(bucketName).object(objectKey).completeMultipartUpload(uploadId, parts)
.then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
jssObject.listAlreadyUploadParts(uploadId) ⇒ Promise.<Response.body> | Promise.<Error>
文件分块上传 展示已经上传的Part
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的Body为空; Promise.<Error> - reject,失败时为错误对象
{
"Bucket":"liningbo",
"Key":"testObject",
"UploadId":"1e34f32a9d1c40ccab504b3c39074dcc",
"PartNumberMarker":0,
"NextPartNumberMarker":null,
"MaxParts":1000,
"HasNext":false,
"Part":[{"PartNumber":1,"LastModified":"Mon, 01 Jul 2013 09:24:27 GMT","ETag":"a46857f0ecc21f0a06ea434b94d9cf1d","Size":30},{"PartNumber":2,"LastModifie d":"Mon, 01 Jul 2013 09:25:43 GMT","ETag":"55032b1ba8bc84b3755818c8a48ea031","Size":52}]
}
Access: public | Param | Type | Description | Require | | --- | --- | --- | --- | | uploadId | String | 分块上传初始化返回的uploadId | Y |
Example
jss.bucket(bucketName).object(objectKey).listAlreadyUploadParts(uploadId)
.then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
jssObject.abortMultipartUpload(uploadId) ⇒ Promise.<Response.body> | Promise.<Error>
文件分块上传 终止批量上传
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的Body为空; Promise.<Error> - reject,失败时为错误对象
Access: public | Param | Type | Description | Require | | --- | --- | --- | --- | | uploadId | String | 分块上传初始化返回的uploadId | Y |
Example
jss.bucket(bucketName).object(objectKey).abortMultipartUpload(uploadId)
.then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
jssObject.listAllUnUploadParts() ⇒ Promise.<Response.body> | Promise.<Error>
文件分块上传 列出还未完成的 Multipart Upload
Kind: instance method of JssObject
Returns: Promise.<Response.body> - resolve,成功时 statusCode 为 200, 返回的Body为空; Promise.<Error> - reject,失败时为错误对象
Access: public
Example
jss.bucket(bucketName).object(objectKey).listAllUnUploadParts()
.then(function (res) {
console.log(res)
}).catch(function (err) {
console.log('出错啦')
console.log(err)
})
更新日志
2.0.0
2018.03.12 升级
put
和putStream
方法升级,fileName可选,如果传递的话,会提示浏览器下载该文件,且文件保存的名字是fileName,如果不想提示浏览器下载,这个参数可以不传。putStream
方法删除contentType参数,具体用法看api说明。
2.0.1
2018.03.12 升级
添加
.npmignore
文件。
2.0.2
2018.03.14 升级
修复Node10版本使用put方法上传时,无法计算文件md5值的问题
put
和putStream
方法返回文件md5值