aliyun-oss
v2.0.0
Published
a new version of oss-client
Downloads
36
Readme
aliyun-oss
- node.js sdk for aliyun oss.
npm install aliyun-oss
aliyun oss
how to use
const OSS = require('aliyun-oss')
const 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
*/
const 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) {});
with webpack
add node stuff in your webpack.config.js
{
node: {
fs: 'empty'
}
}
License
MIT