从相册选取图片上传
选取第一个上传
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| uni.chooseImage({ count: 4, sizeType: ['original', 'compressed'], sourceType: ['album'], success: (res) => { that.$http.upload(that.$config.uploadUrl, { filePath: res.tempFilePaths[0], name: 'file' }) .then(res => { that.myFormData.avatar=res.data.message; }) .catch(err => { that.$tip.error(err.data.message) }); this.imgList = res.tempFilePaths } });
|
选取多个上传
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| let that = this; uni.chooseImage({ count: this.maxImg, sizeType: ['original', 'compressed'], sourceType: ['album','camera'], success: (res) => { let imgs = []; res.tempFiles.forEach((item, index) => { imgs.push({ name: "file"+index, uri: item.path }) });
that.$http.upload(that.$config.uploadUrl, { files: imgs }) .then(res => { console.log(res.data.message); let files = res.data.message.split(','); this.pathlist.concat(files); this.$emit('input',this.pathlist.join(',')) if (this.imgList.length != 0) { this.imgList = this.imgList.concat(files) } else { this.imgList = files } }) .catch(err => { that.$tip.error(err.data.message) }); } });
|
文件服务器使用 FileServer,使用 /FileServer/uploadFiles_App
接口