file formData文件类型的如何同时上传多张图片呢
- 获取到本地相册的图片, 我只能获取到路径一些信息,因为使用的是apicloud拉起的相册,获取的图片信息
- 获得的图片信息我使用canvas转换为formData格式的文件了
- 想请问如何一次上传多张图片以文件流的形式传给后台呢?
convertImgToBase64 (url, callback, outputFormat) {
let that = this
var canvas = document.createElement('CANVAS')
var ctx = canvas.getContext('2d')
var img = new Image;
img.crossOrigin = 'Anonymous';
img.onload = function () {
canvas.height = img.height;
canvas.width = img.width;
let quality = 0.5
ctx.drawImage(img, 0, 0, 400, 400);
var dataURL = canvas.toDataURL(outputFormat || 'image/png', quality);
// let resultFile = that.dataURLtoFile(dataURL)
let resultFile = that.convertBase64UrlToBlob(dataURL) //转换为blob
that.fileList = []
that.fileList.push(resultFile) //转换为file格式的图片
let formData = new FormData()
// formData.append('img_url', that.fileList, 'dbImg')
formData.append('img_url', resultFile, 'dbImg') //如何上传多张图片呢??????????????
formData.append('team_id', that.picParams.team_id)
formData.append('name', that.picParams.name)
formData.append('is_referee', that.picParams.is_referee)
formData.append('open_info', that.picParams.open_info)
formData.append('access_token', localStorage.getItem('access_token'))
formData.append('uid', localStorage.getItem('mid'))
that.$validator.validateAll('commonInfo').then(res => { //开始上传
if (res) {
// that.functionList.push(that.postImg(that.picParams))
that.functionList.push(that.postImg(formData))
async.parallel(that.functionList, (err, result) => {
if (!err) {
console.log('success===>', result);
} else {
console.log('err===>', err);
}
})
} else {
that.$toast(that.$validator.errors.items[0].msg)
return false
}
})
// callback.call(that, dataURL);
canvas = null;
}
img.src = url;
this.canvasImg = img.src
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)