Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
upload.js 2.98 KB
Copy Edit Raw Blame History
大眼睛小怪兽 authored 2018-10-10 11:46 . 初始化
function set_upload_param(up, filename, ret) {
// console.log(filename);
$.ajax({
type: 'POST',
async: false,
url: 'http://my.oss.local/get.php',
data: {'filename':filename},
dataType: 'json',
success: function (result) {
host = result.host;
new_multipart_params = {
'key': result.dir + filename,
'policy': result.policy,
'OSSAccessKeyId': result.accessid,
'success_action_status': '200', //让服务端返回200,不然,默认会返回204
'signature': result.signature,
};
up.setOption({
'url': result.host,
'multipart_params': new_multipart_params
});
up.start();
}
});
}
var uploader = new plupload.Uploader({
runtimes: 'html5,flash,silverlight,html4',
browse_button: 'selectfiles',
//multi_selection: false,
container: document.getElementById('container'),
flash_swf_url: 'lib/plupload-2.1.2/js/Moxie.swf',
silverlight_xap_url: 'lib/plupload-2.1.2/js/Moxie.xap',
url: 'http://oss.aliyuncs.com',
init: {
PostInit: function () {
document.getElementById('ossfile').innerHTML = '';
document.getElementById('postfiles').onclick = function () {
uploader.start();
return false;
};
},
FilesAdded: function (up, files) {
plupload.each(files, function (file) {
document.getElementById('ossfile').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ')<b></b>'
+ '<div class="progress"><div class="progress-bar" style="width: 0%"></div></div>'
+ '</div>';
});
},
BeforeUpload: function (up, file) {
set_upload_param(up, file.name, true);
},
UploadProgress: function (up, file) {
var d = document.getElementById(file.id);
d.getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
var prog = d.getElementsByTagName('div')[0];
var progBar = prog.getElementsByTagName('div')[0]
progBar.style.width = 2 * file.percent + 'px';
progBar.setAttribute('aria-valuenow', file.percent);
},
FileUploaded: function (up, file, info) {
console.log(up, file, info);
if (info.status == 200) {
document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = 'upload to oss success, object name:' + file.name;
}
else {
document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = info.response;
}
},
Error: function (up, err) {
document.getElementById('console').appendChild(document.createTextNode("\nError xml:" + err.response));
}
}
});
uploader.init();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化