function uploadFileTwo(img, token = '') {
reading('show','上传中');
// 配置参数
const config = {
uptoken_url: '/m/base/file/uptoken?type=image',
domain: window.location.protocol + '//upload.qiniu.com/',
max_file_size: '100mb',
max_retries: 3,
chunk_size: '5mb',
filters: {
mime_types: [
{
title: 'Image files',
extensions: 'jpg,gif,png,bmp,jpeg'
}
]
}
};
var oData = new FormData();
oData.append('name', img.name);
oData.append('chunk', '0');
oData.append('chunks', '1');
oData.append('key', 'app52qno_' + img.name);
oData.append('token', token);
oData.append("file", img);
// console.log(oData)
// $.MsgBox.Alert('温馨提示','图片上地址是' + config.domain);
$.ajax({
url: config.domain,
type: 'POST',
data: oData,
processData: false,
contentType: false,
headers: {
'Authorization': 'Bearer ' + token
},
xhr: function() {
var tmpAjaxXhr = $.ajaxSettings.xhr();
if (tmpAjaxXhr.upload) {
tmpAjaxXhr.upload.addEventListener('progress', function(data) {
if (data.lengthComputable) {
var tmptotal = Math.floor(data['loaded'] / data['total'] * 100);
if (tmptotal == 100) {
$(".mask_bg .txt").text('处理中')
} else {
$(".mask_bg .txt").text('上传'+tmptotal+ '%')
}
}
}, false)
};
return tmpAjaxXhr
},
success: function(res) {
console.log('File uploaded successfully:', res);
reading('hide');
// console.log(res)
if(res.size){
res.path = 'http://slfz4v68k.hd-bkt.clouddn.com/' + res.key;
serverImg= (res.path.indexOf('http') >= 0 ? res.path : '/Uploads/'+res.path) ; //https://res.cdn.yqh.com
// imgCall(serverImg); // 隐藏手动拖拽
$("#img").attr("src",serverImg);
newImgCreate();
}else{
$.MsgBox.Alert('温馨提示','图片上传失败,请稍后再试');
}
// return res.path;
},
error: function(res){
reading('hide');
$.MsgBox.Alert('温馨提示','网络错误,请稍后再试!'+ JSON.stringify(res));
}
});
}
上传域名配置下
有问题,好歹说一下吧,谁能猜出来啊JSON.stringify(res)