-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
可以批量上传图片吗? #42
Comments
暂时来说,多图是需要这样上传的
|
例子代码刚好看到这个问题,我把自己项目里上传多张图的代码拿过来。供参考 var that = this;
for (var index = 0; index < images_array.length; index++) {
const path = images_array[index]['crop_src'];
(function (path, index, that) {
qiniuUploader.upload(path, (res) => {
// 上传成功了该干啥干啥
}, (error) => {
console.log('error: ' + error);
wx.showToast({
title: '出错了,请稍后再试',
icon: 'none',
})
}, {
region: 'SCN',
domain: 'https://img.xxx.com',
uptokenURL: 'https://xxx.com/backend/api/v1/upload_token_for_wechat',
}, function (p) {})
})(path, index, that)
} |
我也放一下我的批量上传代码吧全部上传结束后会返回图片链接列表 let uplist = []
for (let index in this.data.images) {
const path = this.data.images[index]['imagePath'];
let promise = new Promise((resolve, reject) => {
qiniuUploader.upload(path, (res) => {
resolve(res.key)
}, (error) => {
reject(error)
});
})
uplist.push(promise)
}
Promise.all(uplist).then((resultList) => {
console.log(resultList)
},error=>{
console.log(error)
wx.showToast({
title: '图片上传失败',
icon: 'none',
duration: 2000,
})
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
比如一次性选了5张图片,我得循环调那个上传接口?
The text was updated successfully, but these errors were encountered: