upload.js
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var $=require('jquery');
var Qiniu=require("../util/qiniu");
var uploader = function(option){
Qiniu.uploader({
runtimes: 'html5,flash,html4',
browse_button: option.button,
uptoken: option.uptoken,
unique_names: true,
multi_selection: false,
filters: {
mime_types: [
{title: "Image files", extensions: "jpg,jpeg,png"}
]
},
dragdrop: false,
domain: option.domain||'http://img01.yohoboys.com/',
max_file_size: '5mb',
max_retries: 3,
chunk_size: '4mb',
auto_start: true,
init: {
'UploadProgress':function(){
},
'FileUploaded': function (up, file, info) {
var imgLink = Qiniu.imageMogr2({
quality: 100, // 图片质量,取值范围1-100
format: 'png'//新图的输出格式,取值范围:jpg,gif,png,webp等
}, info.key);
var domain = up.getOption('domain');
var res = JSON.parse(info);
var sourceLink = domain + res.key+"?"+imgLink;
option.callback&&option.callback(sourceLink);
},
'Error':function(up, err, errTip){
console.log(err);
}
}
});
}
module.exports=uploader;