电脑浏览器 没有任何问题
手机上操作, 就会出现图片上传不上去, 也没有报错, 怀疑是 没有触发上传事件 , 但又 不知道如何修改, 求大神给个 建议。。
来个Demo 那就好极了
这是前端 页面
这是 js 部分 往后端传 , 切显示图片的// 图片上传
onRead(file) {
console.log(file);
console.log('红红火火恍恍惚惚',file.file);
this.headerImg = file.content;
this.$axios.post("http://192.168.1.241:3721/api/qrresume/savePicture", {
file: file,filename: this.resume.applyerName
}).then(resp => {
if (resp.status == 200) {
if (resp.data.status == 200) {
this.resume.imagePath = resp.data.data;
} else {
this.$Message.error("图片上传失败,请重新上传!");
}
}
})
},
这是后端路路由//保存图片
router.post('/savePicture', async (ctx) => {
let base64 = ctx.request.body.file.content;
let filename = ctx.request.body.filename;
let newFileName = Date.now() + "-" + filename + ".jpg";
var base64Data = base64.replace(/^data:image\/\w+;base64,/, "");
var dataBuffer = new Buffer(base64Data, 'base64');
try {
fs.writeFile(`public/upload/photos/${newFileName}/`, dataBuffer, function(err) {});
ctx.body = {
data: newFileName
}
} catch (error) {
throw error
}
})