Upyun storage client
MD5工具函数
函数 | md5() | md5 | |
参数 | data(String) | 待求MD5值的字符串 | |
返回 | String | md5值 |
签名工具函数,详情参见http://docs.upyun.com/api/http_api/#UPYUN签名认证
函数 | signature() | signature | |
参数 | method(String) | HTTP请求方法 | |
参数 | uri(String) | 路径 | |
参数 | date(String) | GMT格式的时间字符串 | |
参数 | contentLength(Number) | 内容长度 | |
参数 | password(String) | 操作员的密码 | |
返回 | String | md5值 |
辅助函数,截获异常,并包装新异常对象
函数 | handle() | handle | |
参数 | callback(Function) | 回调函数 |
辅助函数,截获异常,并包装新异常对象
函数 | Client() | Client | |
参数 | oprator(String) | 操作员 | |
参数 | password(String) | 操作员的密码 | |
参数 | bucket(String) | 又拍云空间名 |
切换又拍云路线
Example:
client.setAddress('v0');
方法 | Client.prototype.setAddress() | setAddress | |
参数 | version(String) | 版本。v0:自动判断,v1:电信,v2:联通网通,v3:移动铁通 |
生成Authorization值
方法 | Client.prototype.getAuthorization() | getAuthorization | |
参数 | method(String) | HTTP请求方法 | |
参数 | uri(String) | 路径 | |
参数 | date(String) | GMT格式的时间字符串 | |
参数 | contentLength(Number) | 内容长度 |
生成urllib的opts对象
函数 | makeOptions() | makeOptions | |
参数 | that(Object) | client对象 | |
参数 | method(String) | HTTP请求方法 | |
参数 | uri(String) | 路径 | |
参数 | filepath(String) | 文件的位置 | |
参数 | size(Number) | 文件大小 |
上传文件
Example:
client.putFile('/path/to/file', '/file.tgz', function (err, data, res) {
// TODO
});
Callback:
err
, 异常对象data
, 得到的数据。本方法中,data中不包含任何信息res
, 响应HTTP response对象。方法 | Client.prototype.putFile() | putFile | |
参数 | filepath(String) | 文件实际地址 | |
参数 | filename(String) | 上传后的位于空间中的位置。假定空间为/,你的文件为file.js,那么就是/file.js | |
参数 | callback(Function) | 回调函数 |
上传文件(通过Buffer)
Example:
var buffer = fs.readFileSync('/path/to/file');
client.putFile(buffer, '/file.tgz', function (err, data, res) {
// TODO
});
Callback:
err
, 异常对象data
, 得到的数据。本方法中,data中不包含任何信息res
, 响应HTTP response对象。方法 | Client.prototype.putBuffer() | putBuffer | |
参数 | buffer(Buffer) | 从文件中读取到的buffer | |
参数 | filename(String) | 上传后的位于空间中的位置。假定空间为/,你的文件为file.js,那么就是/file.js | |
参数 | callback(Function) | 回调函数 |
下载文件
Example:
client.getFile('/file.tgz', function (err, data, res) {
fs.writeFile('/path/to/file', data);
});
Callback:
err
, 异常对象data
, 得到的数据,即文件的Buffer。res
, 响应HTTP response对象。方法 | Client.prototype.getFile() | getFile | |
参数 | filename(String) | 文件位于空间中的位置。 | |
参数 | callback(Function) | 回调函数 |
流式下载文件
Example:
var writable = fs.createWriteStream('/path/to/file');
client.pipe('/file.tgz', writable);
方法 | Client.prototype.pipe() | pipe | |
参数 | filename(String) | 文件位于空间中的位置。 | |
参数 | writable(Stream) | 可写流对象。下载获得的数据会pipe到该writable对象 |
获取文件信息
Example:
client.getFileInfo('/file.tgz', function (err, data, res) {
// data => {type: file, size: 1024, lastModified: some date}
});
Callback:
err
, 异常对象data
, 文件信息,包含type、size和lastModifiedres
, 响应HTTP response对象。方法 | Client.prototype.getFileInfo() | getFileInfo | |
参数 | filename(String) | 文件位于空间中的位置。 | |
参数 | callback(Function) | 回调函数 |
删除文件
Example:
client.deleteFile('/file.tgz', function (err, data, res) {
// TODO
});
Callback:
err
, 异常对象data
, 响应对象。本函数中data无实际意义,没有err,即表示成功res
, 响应HTTP response对象。方法 | Client.prototype.deleteFile() | deleteFile | |
参数 | filename(String) | 文件位于空间中的位置。 | |
参数 | callback(Function) | 回调函数 |
创建文件夹
Example:
client.putFolder('/folder/', function (err, list, res) {
// TODO
});
Callback:
err
, 异常对象data
, 响应对象。本函数中data无实际意义,没有err,即表示成功res
, 响应HTTP response对象。方法 | Client.prototype.putFolder() | putFolder | |
参数 | foldername(String) | 文件夹位于空间中的位置。 | |
参数 | callback(Function) | 回调函数 |
删除文件夹
Example:
client.deleteFolder('/folder/', function (err, list, res) {
// TODO
});
Callback:
err
, 异常对象data
, 响应对象。本函数中data无实际意义,没有err,即表示成功res
, 响应HTTP response对象。属性 | Client.prototype.deleteFolder | deleteFolder | |
参数 | foldername(String) | 文件夹位于空间中的位置。 | |
参数 | callback(Function) | 回调函数 |
获取文件夹的信息
Example:
client.getFolder('/folder/', function (err, list, res) {
// list => [{name: 'test.js', type: 'file', size: 1024, lastModified: new Date()}]
});
Callback:
err
, 异常对象data
, 文件夹信息,包含name、type、size和lastModified的数组res
, 响应HTTP response对象。方法 | Client.prototype.getFolder() | getFolder | |
参数 | dirpath(String) | 文件夹位于空间中的位置。 | |
参数 | callback(Function) | 回调函数 |
获取空间的使用信息
Example:
client.bucketUsage(function (err, used) {
// used => 1024
});
Callback:
err
, 异常对象data
, 使用信息,使用量res
, 响应HTTP response对象方法 | Client.prototype.bucketUsage() | bucketUsage | |
参数 | callback(Function) | 回调函数 |
根据操作员、密码和空间名创建client实例
Example:
var client = Client.create('oprator', 'password', 'bucket');
方法 | Client.create() | Client | create |
参数 | oprator(String) | 操作员 | |
参数 | password(String) | 回调函数 | |
参数 | bucket(String) | 空间名 | |
返回 | Object | 创建的Client实例 |