从相册选取图片上传

选取第一个上传

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
uni.chooseImage({
count: 4, //默认9
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, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album','camera'], //从相册选择
success: (res) => {
let imgs = [];
res.tempFiles.forEach((item, index) => {
imgs.push({
name: "file"+index, //如果 name 不填或填的值相同,可能导致服务端读取文件时只能读取到一个文件
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接口