aliyun-oss-fork
v1.2.0
Published
a new version of oss-client
Downloads
2
Readme
aliyun-oss
node.js sdk for aliyun oss, friendly with co, koa ...
npm install aliyun-oss
aliyun oss
how to use
var OSS = require('aliyun-oss');
var option = {
accessKeyId: 'your access key id',
accessKeySecret: 'your access key secret'
};
/*
* 可选 option
*
* host: default is: oss-cn-hangzhou.aliyuncs.com,
* timeout: default is: 300000,
* agent: default is: agent.maxSockets = 20
*/
var oss = OSS.createClient(option);
summary
params
- bucket - bucket name
- object - object name
- acl - bucket 访问规则, 可选值: 'private', 'public-read', 'public-read-write'
- headers - header
callback params
- error - error
- res - a wrapper of http response, contain
status
,headers
,body
object
创建object
/*
* source: 上传的文件, 可以是文件路径、 buffer、 stream
* headers: 可选,用户自定义 header,如: x-oss-meta-location
* 当上传方式为: buffer 或者 stream, 建议添加 'Content-Type'(此时无法根据扩展名判断)
*/
oss.putObject({
bucket: '',
object: '',
source: '',
headers: {
// optional
'Content-Length': 1024
}
}, function (err, res) {
console.log(res.objectUrl);
});
复制object
oss.copyObject({
bucket: '',
object: '',
sourceBucket: '',
sourceObject: ''
}, function (err, res) {});
删除object
oss.deleteObject({
bucket: '',
object: ''
}, function (err, res) {});
批量删除objects
oss.deleteObjects({
quiet: true, // optional, default is false
bucket: '',
objects: ['']
}, function (err, res) {});
获取object
/*
* dest: 保存object的文件路径 或者 writeStream
* headers: 可选,object类型,用户自定义header,如: If-Unmodified-Since
*/
oss.getObject({
bucket: '',
object: '',
dest: '',
headers: {}
}, function (err, res) {});
获取object头信息
oss.headObject({
bucket: '',
object: ''
}, function (err, res) {});
获取object列表
/*
* prefix: 可选,object 前缀
* marker: 可选,列表起始object
* delimiter: 可选,object分组字符,若'/'为则不列出路径深度大于等于二层的object。
* maxKeys: 可选,列出的object最大个数
*/
oss.listObject({
bucket: '',
prefix: '',
marker: '',
delimiter: '',
maxKeys: ''
}, function (err, res) {});
bucket
列举bucket
oss.listBucket(function (err, res) {});
创建bucket
oss.createBucket({
bucket: '',
acl: ''
}, function (err, res) {});
删除bucket
oss.deleteBucket({
bucket: ''
}, function (err, res) {});
获取bucket访问规则
oss.getBucketAcl({
bucket: ''
}, function (err, res) {});
设置bucket访问规则
oss.setBucketAcl({
bucket: '',
acl: ''
}, function (err, res) {});
use with co
or koa
var option = {
wrapper: 'thunk', // or: promise
accessKeyId: '',
accessKeySecret: ''
};
var oss = OSS.createClient(option);
// in co or koa
yield oss.listBucket();
with webpack
add node stuff in your webpack.config.js
{
node: {
"fs": "empty"
}
}
test
Coverage: 96%
License
MIT