Skip to content

Commit 8cd0a27

Browse files
committed
Merge pull request #118 from qiniu/develop
v1.0.14 release prepare
2 parents 76b19ba + 65622d8 commit 8cd0a27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1468
-25371
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
2-
Gruntfile.js
32
node_modules
3+
bower_components
4+
demo/config.js

.jshintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@
3636
// Enviroments
3737
"browser": true, // globals exposed by modern browsers, like document, window, etc.
3838
"devel": true, // globals that are usually used for logging poor-man's debugging: console, alert, etc.
39-
"jquery": true // jquery library
39+
"jquery": true, // jquery library
40+
41+
"node": true,
42+
"evil": true
4043
}

.travis.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
language: node_js
22
node_js:
33
- "0.12"
4-
- "iojs"
5-
- "iojs-v1.0.4"
4+
cache:
5+
directories:
6+
- node_modules
7+
- bower_components
8+
install:
9+
- npm install
10+
- bower install
11+
script:
12+
- grunt

Gruntfile.coffee

Lines changed: 0 additions & 59 deletions
This file was deleted.

Gruntfile.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
module.exports = function( grunt ) {
2+
3+
"use strict";
4+
5+
grunt.initConfig({
6+
pkg: grunt.file.readJSON('package.json'),
7+
jshint: {
8+
dist: {
9+
src: [ "dist/qiniu.js" ],
10+
options: {
11+
jshintrc: ".jshintrc"
12+
}
13+
},
14+
grunt: {
15+
src: [ "Gruntfile.js" ],
16+
options: {
17+
jshintrc: ".jshintrc"
18+
}
19+
},
20+
},
21+
build: {
22+
all: {
23+
dest: "dist/qiniu.js",
24+
src: ["src/qiniu.js"]
25+
}
26+
},
27+
uglify: {
28+
all: {
29+
files: {
30+
"dist/qiniu.min.js": [ "dist/qiniu.js" ]
31+
},
32+
options: {
33+
banner: "/*! <%= pkg.name %> v<%= pkg.version %> | Copyright 2015 by Qiniu */",
34+
sourceMap: "dist/qiniu.min.map",
35+
compress: {
36+
hoist_funs: false,
37+
join_vars: false,
38+
loops: false,
39+
unused: false
40+
},
41+
beautify: {
42+
ascii_only: true
43+
}
44+
}
45+
}
46+
}
47+
});
48+
49+
grunt.registerMultiTask(
50+
"build",
51+
"Embed date/version",
52+
function() {
53+
54+
var source = grunt.file.read( "src/qiniu.js" ),
55+
version = grunt.config( "pkg.version" );
56+
57+
// Embed Version
58+
// Embed Date
59+
source = source.replace( /@VERSION/g, version )
60+
.replace( "@DATE", function () {
61+
var date = new Date();
62+
63+
// YYYY-MM-DD
64+
return [
65+
date.getFullYear(),
66+
date.getMonth() + 1,
67+
date.getDate()
68+
].join( "-" );
69+
});
70+
71+
// Write concatenated source to file
72+
grunt.file.write( "dist/qiniu.js", source );
73+
74+
// Otherwise, print a success message.
75+
grunt.log.writeln( "File 'dist/qiniu.js' created." );
76+
});
77+
78+
grunt.loadNpmTasks("grunt-contrib-watch");
79+
grunt.loadNpmTasks("grunt-contrib-uglify");
80+
grunt.loadNpmTasks("grunt-contrib-jshint");
81+
grunt.loadNpmTasks("grunt-contrib-copy");
82+
grunt.loadNpmTasks("grunt-contrib-concat");
83+
84+
grunt.registerTask( "default", [ "build", "jshint", "uglify" ] );
85+
};

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ install : all
22

33
all :
44
npm install
5+
bower install
56
grunt
67
node demo/server.js

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,98 @@ qiniu-js-sdk
2727
* Plupload ,建议 2.1.1 及以上版本
2828
* qiniu.js,SDK主体文件,上传功能\数据处理实现
2929

30+
### 常见问题
31+
32+
七牛提供基于plupload插件封装上传的demo `http://jssdk.demo.qiniu.io/`,如果不需要plupload插件可以参考`https://github.com/iwillwen/qiniu.js/tree/develop`,这里主要针对基于plupload插件的方式讲解遇到的一些问题,通过参考plupload文档资料,可以对七牛的demo进行修改,以满足自己的业务需求,plupload插件的使用文档可以参考`http://www.cnblogs.com/2050/p/3913184.html`
33+
34+
**1.关于上传文件命名问题,可以参考:**
35+
在main.js里面,unique_names是plupload插件下面的一个参数,当值为true时会为每个上传的文件生成一个唯一的文件名,这个是plupload插件自动生成的,如果设置成false,七牛这边是会以上传的原始名进行命名的。
36+
1).上传的socpe为bucket的形式,unique_names参数设置为false,上传后文件的key是本地的文件名abc.txt
37+
2).上传的scope为bucket的形式,unique_names参数设置为true,plupload插件会忽略本地文件名,而且这个命名也是没有规律的,上传后文件的key是plupload插件生成的,比如Yc7DZRS1m73o.txt。
38+
3).上传的scope为bucket:key的形式,上传文件本地的名字需要和scope中的key是一致的,不然会报错key doesn‘t match with scope, 注意,这种形式是不能设置unique_names为true的,因为即使上传文件本地名字为abc.txt,但是plupload会给这个文件赋值另外一个文件名。
39+
4).上传的scope为bucket,但是token中有设定saveKey,这种形式save_key是应该设置为true,并且上传的本地文件名也是需要和这个savekey文件名一致的。
40+
5).通过JS前端设置上传的key,在main.js文件里面设置如下:
41+
```
42+
'Key': function(up, file) {
43+
var key = "";
44+
// do something with key
45+
return key
46+
}
47+
```
48+
这个默认是注销的,若想在前端对每个文件的key进行个性化处理,可以配置该函数
49+
该配置必须要在 unique_names: false , save_key: false 时才生效
50+
取消注销后,其优先级要高于:qiniu.js文件中getFileKey。
51+
52+
**2.设置自定义预览样式**
53+
```
54+
该设置在ui.js 文件里,默认为
55+
var imageView =‘?imageView2/1/w/100/h/100’
56+
可修改成
57+
var imageView = ‘样式符+样式名’
58+
```
59+
60+
**3.关于设置取消上传可以参考:**
61+
http://stackoverflow.com/questions/11014384/cancel-file-upload-listener
62+
(文件plupload.dev.js 1950行 removeFile : function(file) 方法)
63+
64+
**4.限制上传文件的类型:**
65+
这里又分为两种方法:
66+
1).通过在token中设定mimeLimit字段限定上传文件的类型,示例
67+
“image/*“表示只允许上传图片类型;
68+
“image/jpeg;image/png”表示只允许上传jpg和png类型的图片;
69+
“!application/json;text/plain”表示禁止上传json文本和纯文本。(注意最前面的感叹号)
70+
2).通过plupload中设定filter参数直接在JS前端限定,如下
71+
```
72+
//可以使用该参数来限制上传文件的类型,大小等,该参数以对象的形式传入,它包括三个属性:
73+
filters : {
74+
max_file_size : '100mb',
75+
prevent_duplicates: true,
76+
//Specify what files to browse for
77+
mime_types: [
78+
{title : "flv files", extensions : "flv"} //限定flv后缀上传格式上传
79+
{title : "Video files", extensions : "flv,mpg,mpeg,avi,wmv,mov,asf,rm,rmvb,mkv,m4v,mp4"}, //限定flv,mpg,mpeg,avi,wmv,mov,asf,rm,rmvb,mkv,m4v,mp4后缀格式上传
80+
{title : "Image files", extensions : "jpg,gif,png"}, //限定jpg,gif,png后缀上传
81+
{title : "Zip files", extensions : "zip"} //限定zip后缀上传
82+
]
83+
},
84+
85+
```
86+
87+
**5.设置每次只能选择一个文件**
88+
通过plupload插件中的multi_selection参数控制,如下
89+
```
90+
//设置一次只能选择一个文件
91+
multi_selection: false,
92+
```
93+
94+
**6.设置取消上传,暂停上传**
95+
在index.html中加入者两个控制按钮:
96+
```
97+
<a class="btn btn-default btn-lg " id="up_load" href="#" >
98+
<span>确认上传</span>
99+
</a>
100+
<a class="btn btn-default btn-lg " id="stop_load" href="#" >
101+
<span>暂停上传</span>
102+
</a>
103+
```
104+
然后在main.js文件里面绑定这两个按钮,添加代码如下:
105+
```
106+
$('#up_load').on('click', function(){
107+
uploader.start();
108+
});
109+
$('#stop_load').on('click', function(){
110+
uploader.stop();
111+
});
112+
```
113+
114+
**7.取消分片上传**
115+
将main.js 里面 chunk_size: '4mb'设置chunk_size: '0mb' ,注意分片上传默认也只能是4M,如果设置一个别的分片的大小会出现上传失败。
116+
117+
**8.取消自动上传**
118+
将main.js文件auto_start参数改成auto_start: false
119+
120+
**9.关于请求token出现跨域**
121+
因为都是建议用户从后端SDK获取token,然后在main.js设置参数uptoken_url: '获取uptoken的url', 这里就有可能出现跨域的现象,此时在服务端添加 response.setHeader("Access-Control-Allow-Origin","*"); 相应头字段即可。
30122

31123
## 安装和运行程序
32124
* 服务端准备
@@ -382,3 +474,5 @@ qiniu-js-sdk
382474
## 基于 GPL V2 协议发布:
383475
384476
> [www.gnu.org/licenses/gpl-2.0.html](http://www.gnu.org/licenses/gpl-2.0.html)
477+
478+

bower.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "qiniu-js-sdk",
3+
"description": "基于七牛API及Plupload开发的前端JavaScript SDK",
4+
"main": "dist/qiniu.js",
5+
"license": "GPL V2",
6+
"homepage": "https://github.com/qiniu/js-sdk",
7+
"moduleType": [],
8+
"private": false,
9+
"ignore": [
10+
"**/.*",
11+
"node_modules",
12+
"bower_components",
13+
"test",
14+
"tests"
15+
],
16+
"dependencies": {
17+
"plupload": "=2.1.1"
18+
},
19+
"devDependencies": {
20+
"bootstrap": "~3.3.6",
21+
"highlight": "~8.9.1",
22+
"jquery": "~1.9.1",
23+
"respond": "~1.4.2"
24+
}
25+
}

0 commit comments

Comments
 (0)