手机拍照然后上传没问题 但是在相册中选择的照片上传 ios手机不行 安卓一部分手机也点击没反应
最后对比了下参数 发现路径有所不同
使用uni.savefile保存路径好在重新上传
savefilesync(tempfilepath){
return new promise((resolve, reject) => {
uni.savefile({
tempfilepath,
success: function (file) {
resolve(file.savedfilepath)
},
fail: function (error) {
reject(error)
}
})
})
}, uni.chooseimage({
count: 1, //默认9
sizetype: ["compressed"], //可以指定是原图还是压缩图,默认二者都
sourcetype: ['camera','album'],
success: async function(result) {
let ewm = result.tempfiles[0]
const path = await that.savefilesync(ewm.path)
if (result.errmsg === "chooseimage:ok") {
result.tempfiles[0].path=path
// that.upload(path);
that.upload(result.tempfiles[0]);
} else {
uni.showtoast({
title: "图片上传失败",
icon: "none",
});
}
},
fail(err) {
uni.showtoast({
title: "取消上传",
icon: "none",
});
},
});upload(event) {
const token = this.gettoken();
// const url = this.getuploadurl();
const imglist = [];
uni.showloading({
title: "上传中...",
mask: true,
});
try {
const [err, res] = await uni.uploadfile({
url: `${host}/resource/file/upload`,
filepath: event.path,
name: "file",
header: {
authorization: token,
},
});
if (res && (res.statuscode === 200)) {
const result = json.parse(res.data);
if (result.code == 200) {
let res1 = json.parse(res.data);
res1.data.uuid = res1.data.id;
res1.data.paramskey = event.name;
imglist.push(res1.data);
const list = [...this.list, ...imglist];
this.$emit("value", list);
this.$emit("change", list);
this.$emit("upload", imglist);
} else {
wx.showtoast({
icon: "none",
title: result.msg,
});
}
} else {
wx.showtoast({
icon: "error",
title: "上传失败",
});
}
} catch (error) {
console.log(error)
}
uni.hideloading();
this.$emit("upload", imglist);
},到此这篇关于uniapp在开发app时上传文件时的问题的文章就介绍到这了,更多相关uniapp上传文件内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论