前端代码:
<input
id="filePath"
type="file"
@change="uploadFile($event)"
multiple="multiple"
/>
uploadFile(event) {
let formData = new FormData();
let file = event.target.files[0];
console.log(event.target.files[0])
//把文件信息放入对象中
formData.append("key", file.type);
let config = {
headers: {
"Content-Type": "multipart/form-data",
},
};
axios.post('upload/img',formData,config).then(res=>{
console.log(res);
})
}
后端controller代码
const {
ctx
} = this
console.log('=====')
let stream = await ctx.getFileStream() // 文件上传
console.log(stream)
后端终端报错:
message: "Can't found upload file"
pid: 13756
我对ctx.getFileStream 不是很懂,百度了的理解就是会接收前端传递过来的 formData数据
现在是使用 ctx.getFileStream 就会报上面错
config/config.default.js 配置了
config.multipart = {
mode: 'stream',
};