init
This commit is contained in:
169
fuintUniapp/utils/request/upload/qiniuUploader.js
Normal file
169
fuintUniapp/utils/request/upload/qiniuUploader.js
Normal file
@@ -0,0 +1,169 @@
|
||||
// created by gpake
|
||||
(function () {
|
||||
|
||||
var config = {
|
||||
qiniuRegion: '',
|
||||
qiniuImageURLPrefix: '',
|
||||
qiniuUploadToken: '',
|
||||
qiniuUploadTokenURL: '',
|
||||
qiniuUploadTokenFunction: null,
|
||||
qiniuShouldUseQiniuFileName: false
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init,
|
||||
upload: upload,
|
||||
}
|
||||
|
||||
// 在整个程序生命周期中,只需要 init 一次即可
|
||||
// 如果需要变更参数,再调用 init 即可
|
||||
function init(options) {
|
||||
config = {
|
||||
qiniuRegion: '',
|
||||
qiniuImageURLPrefix: '',
|
||||
qiniuUploadToken: '',
|
||||
qiniuUploadTokenURL: '',
|
||||
qiniuUploadTokenFunction: null,
|
||||
qiniuShouldUseQiniuFileName: false
|
||||
};
|
||||
updateConfigWithOptions(options);
|
||||
}
|
||||
|
||||
function updateConfigWithOptions(options) {
|
||||
if (options.region) {
|
||||
config.qiniuRegion = options.region;
|
||||
} else {
|
||||
console.error('qiniu uploader need your bucket region');
|
||||
}
|
||||
if (options.uptoken) {
|
||||
config.qiniuUploadToken = options.uptoken;
|
||||
} else if (options.uptokenURL) {
|
||||
config.qiniuUploadTokenURL = options.uptokenURL;
|
||||
} else if (options.uptokenFunc) {
|
||||
config.qiniuUploadTokenFunction = options.uptokenFunc;
|
||||
}
|
||||
if (options.domain) {
|
||||
config.qiniuImageURLPrefix = options.domain;
|
||||
}
|
||||
config.qiniuShouldUseQiniuFileName = options.shouldUseQiniuFileName
|
||||
}
|
||||
|
||||
function upload(filePath, success, fail, options, progress, cancelTask) {
|
||||
if (null == filePath) {
|
||||
console.error('qiniu uploader need filePath to upload');
|
||||
return;
|
||||
}
|
||||
if (options) {
|
||||
updateConfigWithOptions(options);
|
||||
}
|
||||
if (config.qiniuUploadToken) {
|
||||
doUpload(filePath, success, fail, options, progress, cancelTask);
|
||||
} else if (config.qiniuUploadTokenURL) {
|
||||
getQiniuToken(function () {
|
||||
doUpload(filePath, success, fail, options, progress, cancelTask);
|
||||
});
|
||||
} else if (config.qiniuUploadTokenFunction) {
|
||||
config.qiniuUploadToken = config.qiniuUploadTokenFunction();
|
||||
if (null == config.qiniuUploadToken && config.qiniuUploadToken.length > 0) {
|
||||
console.error('qiniu UploadTokenFunction result is null, please check the return value');
|
||||
return
|
||||
}
|
||||
doUpload(filePath, success, fail, options, progress, cancelTask);
|
||||
} else {
|
||||
console.error('qiniu uploader need one of [uptoken, uptokenURL, uptokenFunc]');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function doUpload(filePath, success, fail, options, progress, cancelTask) {
|
||||
if (null == config.qiniuUploadToken && config.qiniuUploadToken.length > 0) {
|
||||
console.error('qiniu UploadToken is null, please check the init config or networking');
|
||||
return
|
||||
}
|
||||
var url = uploadURLFromRegionCode(config.qiniuRegion);
|
||||
var fileName = filePath.split('//')[1];
|
||||
if (options && options.key) {
|
||||
fileName = options.key;
|
||||
}
|
||||
var formData = {
|
||||
'token': config.qiniuUploadToken
|
||||
};
|
||||
if (!config.qiniuShouldUseQiniuFileName) {
|
||||
formData['key'] = fileName
|
||||
}
|
||||
var uploadTask = wx.uploadFile({
|
||||
url: url,
|
||||
filePath: filePath,
|
||||
name: 'file',
|
||||
formData: formData,
|
||||
success: function (res) {
|
||||
var dataString = res.data
|
||||
if (res.data.hasOwnProperty('type') && res.data.type === 'Buffer') {
|
||||
dataString = String.fromCharCode.apply(null, res.data.data)
|
||||
}
|
||||
try {
|
||||
var dataObject = JSON.parse(dataString);
|
||||
//do something
|
||||
var imageUrl = config.qiniuImageURLPrefix + '/' + dataObject.key;
|
||||
dataObject.imageURL = imageUrl;
|
||||
if (success) {
|
||||
success(dataObject);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('parse JSON failed, origin String is: ' + dataString)
|
||||
if (fail) {
|
||||
fail(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function (error) {
|
||||
console.error(error);
|
||||
if (fail) {
|
||||
fail(error);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
uploadTask.onProgressUpdate((res) => {
|
||||
progress && progress(res)
|
||||
})
|
||||
|
||||
cancelTask && cancelTask(() => {
|
||||
uploadTask.abort()
|
||||
})
|
||||
}
|
||||
|
||||
function getQiniuToken(callback) {
|
||||
wx.request({
|
||||
url: config.qiniuUploadTokenURL,
|
||||
success: function (res) {
|
||||
var token = res.data.uptoken;
|
||||
if (token && token.length > 0) {
|
||||
config.qiniuUploadToken = token;
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
} else {
|
||||
console.error('qiniuUploader cannot get your token, please check the uptokenURL or server')
|
||||
}
|
||||
},
|
||||
fail: function (error) {
|
||||
console.error('qiniu UploadToken is null, please check the init config or networking: ' + error);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function uploadURLFromRegionCode(code) {
|
||||
var uploadURL = null;
|
||||
switch (code) {
|
||||
case 'ECN': uploadURL = 'https://up.qbox.me'; break;
|
||||
case 'NCN': uploadURL = 'https://up-z1.qbox.me'; break;
|
||||
case 'SCN': uploadURL = 'https://up-z2.qbox.me'; break;
|
||||
case 'NA': uploadURL = 'https://up-na0.qbox.me'; break;
|
||||
case 'ASG': uploadURL = 'https://up-as0.qbox.me'; break;
|
||||
default: console.error('please make the region is with one of [ECN, SCN, NCN, NA, ASG]');
|
||||
}
|
||||
return uploadURL;
|
||||
}
|
||||
|
||||
})();
|
||||
208
fuintUniapp/utils/request/upload/upload.js
Normal file
208
fuintUniapp/utils/request/upload/upload.js
Normal file
@@ -0,0 +1,208 @@
|
||||
import request from "./../core/request.js";
|
||||
const {
|
||||
chooseImage,
|
||||
chooseVideo,
|
||||
qiniuUpload,
|
||||
urlUpload
|
||||
} = require("./utils");
|
||||
import {
|
||||
mergeConfig
|
||||
} from "./../core/utils.js";
|
||||
export default class fileUpload extends request {
|
||||
constructor(props) {
|
||||
// 调用实现父类的构造函数
|
||||
super(props);
|
||||
}
|
||||
//七牛云上传图片
|
||||
async qnImgUpload(options = {}) {
|
||||
let files;
|
||||
try {
|
||||
files = await chooseImage(options);
|
||||
// 选择完成回调
|
||||
options.onSelectComplete && options.onSelectComplete(files);
|
||||
} catch (err) {
|
||||
this.requestError && this.requestError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
if (files) {
|
||||
return this.qnFileUpload({
|
||||
...options,
|
||||
files: files
|
||||
});
|
||||
}
|
||||
}
|
||||
//七牛云上传视频
|
||||
async qnVideoUpload(options = {}) {
|
||||
let files;
|
||||
try {
|
||||
files = await chooseVideo(options);
|
||||
// 选择完成回调
|
||||
options.onSelectComplete && options.onSelectComplete(files);
|
||||
} catch (err) {
|
||||
this.requestError && this.requestError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
if (files) {
|
||||
return this.qnFileUpload({
|
||||
...options,
|
||||
files: files
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//七牛云文件上传(支持多张上传)
|
||||
async qnFileUpload(options = {}) {
|
||||
let requestInfo;
|
||||
try {
|
||||
// 数据合并
|
||||
requestInfo = {
|
||||
...this.config,
|
||||
...options,
|
||||
header: {},
|
||||
method: "FILE"
|
||||
};
|
||||
//请求前回调
|
||||
if (this.requestStart) {
|
||||
let requestStart = this.requestStart(requestInfo);
|
||||
if (typeof requestStart == "object") {
|
||||
let changekeys = ["load", "files"];
|
||||
changekeys.forEach(key => {
|
||||
requestInfo[key] = requestStart[key];
|
||||
});
|
||||
} else {
|
||||
throw {
|
||||
errMsg: "【request】请求开始拦截器未通过",
|
||||
statusCode: 0,
|
||||
data: requestInfo.data,
|
||||
method: requestInfo.method,
|
||||
header: requestInfo.header,
|
||||
url: requestInfo.url,
|
||||
}
|
||||
}
|
||||
}
|
||||
let requestResult = await qiniuUpload(requestInfo, this.getQnToken);
|
||||
return Promise.resolve(requestResult);
|
||||
} catch (err) {
|
||||
this.requestError && this.requestError(err);
|
||||
return Promise.reject(err);
|
||||
} finally {
|
||||
this.requestEnd && this.requestEnd(requestInfo);
|
||||
}
|
||||
}
|
||||
//本地服务器图片上传
|
||||
async urlImgUpload() {
|
||||
let options = {};
|
||||
if (arguments[0]) {
|
||||
if (typeof(arguments[0]) == "string") {
|
||||
options.url = arguments[0];
|
||||
} else if (typeof(arguments[0]) == "object") {
|
||||
options = Object.assign(options, arguments[0]);
|
||||
}
|
||||
}
|
||||
if (arguments[1] && typeof(arguments[1]) == "object") {
|
||||
options = Object.assign(options, arguments[1]);
|
||||
}
|
||||
try {
|
||||
options.files = await chooseImage(options);
|
||||
// 选择完成回调
|
||||
options.onSelectComplete && options.onSelectComplete(options.files);
|
||||
} catch (err) {
|
||||
this.requestError && this.requestError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
if (options.files) {
|
||||
return this.urlFileUpload(options);
|
||||
}
|
||||
}
|
||||
//本地服务器上传视频
|
||||
async urlVideoUpload() {
|
||||
let options = {};
|
||||
if (arguments[0]) {
|
||||
if (typeof(arguments[0]) == "string") {
|
||||
options.url = arguments[0];
|
||||
} else if (typeof(arguments[0]) == "object") {
|
||||
options = Object.assign(options, arguments[0]);
|
||||
}
|
||||
}
|
||||
if (arguments[1] && typeof(arguments[1]) == "object") {
|
||||
options = Object.assign(options, arguments[1]);
|
||||
}
|
||||
try {
|
||||
options.files = await chooseVideo(options);
|
||||
// 选择完成回调
|
||||
options.onSelectComplete && options.onSelectComplete(options.files);
|
||||
} catch (err) {
|
||||
this.requestError && this.requestError(err);
|
||||
return Promise.reject(err);
|
||||
}
|
||||
if (options.files) {
|
||||
return this.urlFileUpload(options);
|
||||
}
|
||||
}
|
||||
//本地服务器文件上传方法
|
||||
async urlFileUpload() {
|
||||
let requestInfo = {
|
||||
method: "FILE"
|
||||
};
|
||||
if (arguments[0]) {
|
||||
if (typeof(arguments[0]) == "string") {
|
||||
requestInfo.url = arguments[0];
|
||||
} else if (typeof(arguments[0]) == "object") {
|
||||
requestInfo = Object.assign(requestInfo, arguments[0]);
|
||||
}
|
||||
}
|
||||
if (arguments[1] && typeof(arguments[1]) == "object") {
|
||||
requestInfo = Object.assign(requestInfo, arguments[1]);
|
||||
}
|
||||
if (!requestInfo.url && this.defaultUploadUrl) {
|
||||
requestInfo.url = this.defaultUploadUrl;
|
||||
}
|
||||
// 请求数据
|
||||
// 是否运行过请求开始钩子
|
||||
let runRequestStart = false;
|
||||
try {
|
||||
if (!requestInfo.url) {
|
||||
throw {
|
||||
errMsg: "【request】文件上传缺失数据url",
|
||||
statusCode: 0,
|
||||
data: requestInfo.data,
|
||||
method: requestInfo.method,
|
||||
header: requestInfo.header,
|
||||
url: requestInfo.url,
|
||||
}
|
||||
}
|
||||
// 数据合并
|
||||
requestInfo = mergeConfig(this, requestInfo);
|
||||
// 代表之前运行到这里
|
||||
runRequestStart = true;
|
||||
//请求前回调
|
||||
if (this.requestStart) {
|
||||
let requestStart = this.requestStart(requestInfo);
|
||||
if (typeof requestStart == "object") {
|
||||
let changekeys = ["data", "header", "isPrompt", "load", "isFactory", "files"];
|
||||
changekeys.forEach(key => {
|
||||
requestInfo[key] = requestStart[key];
|
||||
});
|
||||
} else {
|
||||
throw {
|
||||
errMsg: "【request】请求开始拦截器未通过",
|
||||
statusCode: 0,
|
||||
data: requestInfo.data,
|
||||
method: requestInfo.method,
|
||||
header: requestInfo.header,
|
||||
url: requestInfo.url,
|
||||
}
|
||||
}
|
||||
}
|
||||
let requestResult = await urlUpload(requestInfo, this.dataFactory);
|
||||
return Promise.resolve(requestResult);
|
||||
} catch (err) {
|
||||
this.requestError && this.requestError(err);
|
||||
return Promise.reject(err);
|
||||
} finally {
|
||||
if (runRequestStart) {
|
||||
this.requestEnd && this.requestEnd(requestInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
288
fuintUniapp/utils/request/upload/utils.js
Normal file
288
fuintUniapp/utils/request/upload/utils.js
Normal file
@@ -0,0 +1,288 @@
|
||||
const qiniuUploader = require("./qiniuUploader");
|
||||
//七牛云上传文件命名
|
||||
export const randomChar = function(l, url = "") {
|
||||
const x = "0123456789qwertyuioplkjhgfdsazxcvbnm";
|
||||
let tmp = "";
|
||||
let time = new Date();
|
||||
for (let i = 0; i < l; i++) {
|
||||
tmp += x.charAt(Math.ceil(Math.random() * 100000000) % x.length);
|
||||
}
|
||||
return (
|
||||
"file/" +
|
||||
url +
|
||||
time.getTime() +
|
||||
tmp
|
||||
);
|
||||
}
|
||||
//图片选择
|
||||
export const chooseImage = function(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.chooseImage({
|
||||
count: data.count || 9, //默认9
|
||||
sizeType: data.sizeType || ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
|
||||
sourceType: data.sourceType || ['album', 'camera'], //从相册选择
|
||||
success: function(res) {
|
||||
resolve(res.tempFiles);
|
||||
},
|
||||
fail: err => {
|
||||
reject({
|
||||
errMsg: err.errMsg,
|
||||
errCode: err.errCode,
|
||||
statusCode: 0,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
//视频选择
|
||||
export const chooseVideo = function(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.chooseVideo({
|
||||
sourceType: data.sourceType || ['album', 'camera'], //从相册选择
|
||||
compressed: data.compressed || false, //是否压缩所选的视频源文件,默认值为 true,需要压缩。
|
||||
maxDuration: data.maxDuration || 60, //拍摄视频最长拍摄时间,单位秒。最长支持 60 秒。
|
||||
camera: data.camera || 'back', //'front'、'back',默认'back'
|
||||
success: function(res) {
|
||||
let files = [{
|
||||
path: res.tempFilePath
|
||||
}];
|
||||
// #ifdef APP-PLUS || H5 || MP-WEIXIN
|
||||
files[0].duration = res.duration;
|
||||
files[0].size = res.size;
|
||||
files[0].height = res.height;
|
||||
files[0].width = res.width;
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
files[0].name = res.name;
|
||||
// #endif
|
||||
resolve(files);
|
||||
},
|
||||
fail: err => {
|
||||
reject({
|
||||
errMsg: err.errMsg,
|
||||
errCode: err.errCode,
|
||||
statusCode: 0,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// 七牛云上传
|
||||
export const qiniuUpload = function(requestInfo, getQnToken) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (Array.isArray(requestInfo.files)) {
|
||||
let len = requestInfo.files.length;
|
||||
let fileList = new Array;
|
||||
if (getQnToken) {
|
||||
getQnToken(qnRes => {
|
||||
/*
|
||||
*接口返回参数:
|
||||
*visitPrefix:访问文件的域名
|
||||
*token:七牛云上传token
|
||||
*folderPath:上传的文件夹
|
||||
*region: 地区 默认为:SCN
|
||||
*/
|
||||
let prefixLen = qnRes.visitPrefix.length;
|
||||
if(qnRes.visitPrefix.charAt(prefixLen - 1) == '/'){
|
||||
qnRes.visitPrefix = qnRes.visitPrefix.substring(0, prefixLen - 1)
|
||||
}
|
||||
uploadFile(0);
|
||||
|
||||
function uploadFile(i) {
|
||||
let item = requestInfo.files[i];
|
||||
let updateUrl = randomChar(10, qnRes.folderPath);
|
||||
let fileData = {
|
||||
fileIndex: i,
|
||||
files: requestInfo.files,
|
||||
...item
|
||||
};
|
||||
if (item.name) {
|
||||
fileData.name = item.name;
|
||||
let nameArr = item.name.split(".");
|
||||
updateUrl += "." + nameArr[nameArr.length - 1];
|
||||
}
|
||||
// 交给七牛上传
|
||||
qiniuUploader.upload(item.path || item, (res) => {
|
||||
fileData.url = res.imageURL;
|
||||
requestInfo.onEachUpdate && requestInfo.onEachUpdate({
|
||||
url: res.imageURL,
|
||||
...fileData
|
||||
});
|
||||
fileList.push(res.imageURL);
|
||||
if (len - 1 > i) {
|
||||
uploadFile(i + 1);
|
||||
} else {
|
||||
resolve(fileList);
|
||||
}
|
||||
}, (error) => {
|
||||
reject(error);
|
||||
}, {
|
||||
region: qnRes.region || 'SCN', //地区
|
||||
domain: qnRes.visitPrefix, // bucket 域名,下载资源时用到。
|
||||
key: updateUrl,
|
||||
uptoken: qnRes.token, // 由其他程序生成七牛 uptoken
|
||||
uptokenURL: 'UpTokenURL.com/uptoken' // 上传地址
|
||||
}, (res) => {
|
||||
console.log(requestInfo);
|
||||
requestInfo.onProgressUpdate && requestInfo.onProgressUpdate(Object.assign({}, fileData, res));
|
||||
// console.log('上传进度', res.progress)
|
||||
// console.log('已经上传的数据长度', res.totalBytesSent)
|
||||
// console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
reject({
|
||||
errMsg: "请添加七牛云回调方法:getQnToken",
|
||||
statusCode: 0
|
||||
});
|
||||
}
|
||||
} else {
|
||||
reject({
|
||||
errMsg: "files 必须是数组类型",
|
||||
statusCode: 0
|
||||
});
|
||||
};
|
||||
});
|
||||
}
|
||||
// 服务器URL上传
|
||||
export const urlUpload = function(requestInfo, dataFactory) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 本地文件上传去掉默认Content-Type
|
||||
if (requestInfo.header['Content-Type']) {
|
||||
delete requestInfo.header['Content-Type'];
|
||||
}
|
||||
// 本地文件上传去掉默认Content-Type
|
||||
if (requestInfo.header['content-type']) {
|
||||
delete requestInfo.header['content-type'];
|
||||
}
|
||||
if (Array.isArray(requestInfo.files)) {
|
||||
// // #ifdef APP-PLUS || H5
|
||||
// let files = [];
|
||||
// let fileData = {
|
||||
// files: requestInfo.files,
|
||||
// name: requestInfo.name || "file"
|
||||
// };
|
||||
// requestInfo.files.forEach(item => {
|
||||
// let fileInfo = {
|
||||
// name: requestInfo.name || "file",
|
||||
// };
|
||||
// if(item.path){
|
||||
// fileInfo.uri = item.path;
|
||||
// } else {
|
||||
// fileInfo.file = item;
|
||||
// }
|
||||
// files.push(fileInfo);
|
||||
// });
|
||||
// let config = {
|
||||
// url: requestInfo.url,
|
||||
// files: files,
|
||||
// header: requestInfo.header, //加入请求头
|
||||
// success: (response) => {
|
||||
// //是否用外部的数据处理方法
|
||||
// if (requestInfo.isFactory && dataFactory) {
|
||||
// //数据处理
|
||||
// dataFactory({
|
||||
// ...requestInfo,
|
||||
// response: response,
|
||||
// }).then(data => {
|
||||
// requestInfo.onEachUpdate && requestInfo.onEachUpdate({
|
||||
// data: data,
|
||||
// ...fileData
|
||||
// });
|
||||
// resolve(data);
|
||||
// },err => {
|
||||
// reject(err);
|
||||
// });
|
||||
// } else {
|
||||
// requestInfo.onEachUpdate && requestInfo.onEachUpdate({
|
||||
// data: response,
|
||||
// ...fileData
|
||||
// });
|
||||
// resolve(response);
|
||||
// }
|
||||
// },
|
||||
// fail: (err) => {
|
||||
// reject(err);
|
||||
// }
|
||||
// };
|
||||
// if (requestInfo.data) {
|
||||
// config.formData = requestInfo.data;
|
||||
// }
|
||||
// const uploadTask = uni.uploadFile(config);
|
||||
// uploadTask.onProgressUpdate(res => {
|
||||
// requestInfo.onProgressUpdate && requestInfo.onProgressUpdate(Object.assign({}, fileData, res));
|
||||
// });
|
||||
// // #endif
|
||||
// #-ifdef MP
|
||||
const len = requestInfo.files.length - 1;
|
||||
let fileList = new Array;
|
||||
fileUpload(0);
|
||||
|
||||
function fileUpload(i) {
|
||||
let item = requestInfo.files[i];
|
||||
let fileData = {
|
||||
fileIndex: i,
|
||||
files: requestInfo.files,
|
||||
...item
|
||||
};
|
||||
let config = {
|
||||
url: requestInfo.url,
|
||||
filePath: item.path,
|
||||
header: requestInfo.header, //加入请求头
|
||||
name: requestInfo.name || "file",
|
||||
success: (response) => {
|
||||
//是否用外部的数据处理方法
|
||||
if (requestInfo.isFactory && dataFactory) {
|
||||
//数据处理
|
||||
dataFactory({
|
||||
...requestInfo,
|
||||
response: response,
|
||||
}).then(data => {
|
||||
fileList.push(data);
|
||||
requestInfo.onEachUpdate && requestInfo.onEachUpdate({
|
||||
data: data,
|
||||
...fileData
|
||||
});
|
||||
if (len <= i) {
|
||||
resolve(fileList);
|
||||
} else {
|
||||
fileUpload(i + 1);
|
||||
}
|
||||
},err => {
|
||||
reject(err);
|
||||
});
|
||||
} else {
|
||||
requestInfo.onEachUpdate && requestInfo.onEachUpdate({
|
||||
data: response,
|
||||
...fileData
|
||||
});
|
||||
fileList.push(response);
|
||||
if (len <= i) {
|
||||
resolve(fileList);
|
||||
} else {
|
||||
fileUpload(i + 1);
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
if (requestInfo.data) {
|
||||
config.formData = requestInfo.data;
|
||||
}
|
||||
const uploadTask = uni.uploadFile(config);
|
||||
uploadTask.onProgressUpdate(res => {
|
||||
requestInfo.onProgressUpdate && requestInfo.onProgressUpdate(Object.assign({}, fileData, res));
|
||||
});
|
||||
}
|
||||
// #-endif
|
||||
} else {
|
||||
reject({
|
||||
errMsg: "files 必须是数组类型",
|
||||
statusCode: 0
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user