Skip to content
xianjimli edited this page May 23, 2014 · 4 revisions

js-sdk-for-UPYUN 是为UPYUN(又拍云)开发的JavaScript SDK,开发人员可以在浏览器中直接使用UPYUN(又拍云)的AP 化WebApp存储方面的工作量。

0.获取upyun对象(工厂方法)。


函数原型

function getUpYunClient();

参数说明

  • bucket bucket名称
  • username 用户名
  • password 密码
  • onDone 完成时的回调函数,函数原型:onDone = function(result, message)。result为true表示成功,false表示失败。

示例代码

var upyun = getUpYunClient();

1.登录-login


函数原型

function getUpYunClient();

参数说明

  • bucket bucket名称
  • username 用户名
  • password 密码
  • onDone 完成时的回调函数,函数原型:onDone = function(result, message)。result为true表示成功,false表示失败。

示例代码

upyun.login("www.drawapp8.com", "drawapp8", "123456", function(result, message) {
  //TODO:
});

2.上传文件


函数原型

UpYun.prototype.writeFile = function(path, file, onDone, options)

参数说明

  • path 全路径文件名
  • file 文件句柄(通过让用户选择获得)。
  • onDone 完成时的回调函数,函数原型:onDone = function(result, message)。result为true表示成功,false表示失败。
  • options 选项(数组),具体请参考接口文档

示例代码

upyun.writeFile("/test.txt", file, function(result, message) {
  //TODO:
});

3.上传数据

(对于创建内容的WebApp非常有用,可以方便的把生成的数据存到UPYUN(又拍云)上)


函数原型

UpYun.prototype.writeData = function(path, data, onDone, options)

参数说明

  • path 全路径文件名
  • file 文件句柄(通过让用户选择获得)。
  • onDone 完成时的回调函数,函数原型:onDone = function(result, message)。result为true表示成功,false表示失败。
  • options 选项(数组),具体请参考接口文档

示例代码

upyun.writeData("/test.txt", data, function(result, message) {
  //TODO:
});

4.下载文件


函数原型

UpYun.prototype.read = function(path, onDone)

参数说明

  • path 全路径文件名
  • onDone 完成时的回调函数,函数原型:onDone = function(path, content)。content为文件内容。

示例代码

upyun.read("/test.txt", function(path, content) {
  //TODO:
});

5.获取文件信息-getFileInfo


函数原型

UpYun.prototype.getFileInfo = function(path, onDone)

参数说明

  • path 全路径文件名
  • onDone 完成时的回调函数,函数原型:onDone = function(result, message, data)。result为true表示成功,false表示失败。

示例代码

upyun.getFileInfo("/test.txt", function(result, message, data) {
  //TODO:
});

6.删除文件/目录


函数原型

UpYun.prototype.delete = function(path, onDone)

参数说明

  • path 全路径文件名
  • onDone 完成时的回调函数,函数原型:onDone = function(result, message)。result为true表示成功,false表示失败。

示例代码

upyun.delete("/test.txt", function(result, message) {
  //TODO:
});

7.创建目录


函数原型

UpYun.prototype.makeDir = function(path, onDone)

参数说明

  • path 全路径文件名
  • onDone 完成时的回调函数,函数原型:onDone = function(result, message)。result为true表示成功,false表示失败。

示例代码

upyun.makeDir("/abc", function(result, message) {
  //TODO:
});

8.获取目录文件列表


函数原型

UpYun.prototype.list = function(path, onDone)

参数说明

  • path 全路径文件名
  • onDone 完成时的回调函数,函数原型:onDone = function(result, message, data)。result为true表示成功,false表示失败。

示例代码

upyun.list("/", function(result, message, data) {
  //TODO:
});

9.获取空间使用情况


函数原型

UpYun.prototype.getFolderUsage = function(path, onDone)

参数说明

  • path 全路径文件名
  • onDone 完成时的回调函数,函数原型:onDone = function(result, message, data)。result为true表示成功,false表示失败。

示例代码

upyun.getFolderUsage("/", function(result, message, data) {
  //TODO:
});

10.拷贝文件


函数原型

UpYun.prototype.copy = function(srcName, dstName, onDone) 

参数说明

  • srcName 全路径源文件名
  • dstName 全路径目的文件名
  • onDone 完成时的回调函数,函数原型:onDone = function(result, message)。result为true表示成功,false表示失败。

示例代码

upyun.copy("/src.txt", "/dst.txt", function(result, message) {
  //TODO:
});

11.移动文件


函数原型

UpYun.prototype.move = function(srcName, dstName, onDone) 

参数说明

  • srcName 全路径源文件名
  • dstName 全路径目的文件名
  • onDone 完成时的回调函数,函数原型:onDone = function(result, message)。result为true表示成功,false表示失败。

示例代码

upyun.move("/src.txt", "/dst.txt", function(result, message) {
  //TODO:
});

12.重命名文件


函数原型

UpYun.prototype.rename = function(srcName, dstName, onDone) 

参数说明

  • srcName 全路径源文件名
  • dstName 全路径目的文件名
  • onDone 完成时的回调函数,函数原型:onDone = function(result, message)。result为true表示成功,false表示失败。

示例代码

upyun.rename("/src.txt", "/dst.txt", function(result, message) {
  //TODO:
});

13.检查用户是否登录-isLogined


函数原型

UpYun.prototype.isLogined = function(onDone)

参数说明

  • onDone 完成时的回调函数,函数原型:onDone = function(result, message)。result为true表示成功,false表示失败。

示例代码

upyun.isLogined(function(result, message) {
  //TODO:
});

14.退出


函数原型

UpYun.prototype.logout = function(onDone)

参数说明

  • onDone 完成时的回调函数,函数原型:onDone = function(result, message)。result为true表示成功,false表示失败。

示例代码

upyun.logout(function(result, message) {
  //TODO:
});

Clone this wiki locally