All Projects → upyun → js-multipart-upload

upyun / js-multipart-upload

Licence: other
HTML5 multipart-uploader demo

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

upyun-multipart-upload

使用 HTML 5 相关 API 开发的分块上传 DEMO

在您决定将本项目用于生产环境之前,请确保知晓如何保护表单密钥的安全性,以及本项目在部分低配设备上可能会有的兼容性和性能问题!

安装

你可以通过如下两种方式中任意一种引入本项目:

1.bower

$ bower install --save upyun-multipart-upload

2.直接下载

  1. 下载本项目最新的 Release
  2. 下载依赖 async
  3. 下载依赖 SparkMD5
  4. 通过 <script src=""></script> 标签以此引入文件,注意将依赖放在前面
<script src="/path/to/spark-md5/spark-md5.js"></script>
<script src="/path/to/async/lib/async.js"></script>
<script src="/path/to/js-multipart-upload/lib/upyun-mu.js"></script>

Usage

eg:

document.getElementById('submit').onclick = function() {
    var ext = '.' + document.getElementById('file').files[0].name.split('.').pop();

    var config = {
        bucket: 'demonstration',
        expiration: parseInt((new Date().getTime() + 3600000) / 1000),
        signature: 'something'
    };

    var instance = new Sand(config);
    var options = {
        'notify_url': 'http://upyun.com'
    };

    instance.setOptions(options);
    instance.upload('/upload/test' + parseInt((new Date().getTime() + 3600000) / 1000) + ext);
};

API

构建实例

new Sand(config);

参数说明

  • config 必要参数
    • bucket: 空间名称
    • expiration: 上传请求过期时间(单位为:
    • signature: 初始化上传所需的签名
    • form_api_secret: 表单 API (慎用)

注意

其中 signatureform_api_secret 为互斥项,为了避免表单 API 泄露造成安全隐患,请尽可能根据所需参数自行传入初始化上传所需的 signature 参数

计算签名算法,请参考文档

设置额外上传参数

instance.setOptions(options)

参数说明

  • options: Object 类型,包含额外的上传参数(详情见 表单 API Policy

上传

instance.upload(path)

参数说明

  • path: 文件在空间中的存放路径

事件

uploaded

上传完成后,会触发自定义事件 uploaded, 在事件对象中,会包含一些基本的信息,以供使用

error

上传出错,会触发自定义事件 error, 在事件对象中,会包含错误的详情

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].