是小圆子鸭 2022-05-12 11:41 采纳率: 50%
浏览 95
已结题

egg.js实现图片上传到本地遇到的问题

前端代码:

<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',
};

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 5月20日
    • 创建了问题 5月12日

    悬赏问题

    • ¥15 c++ gmssl sm2验签demo
    • ¥15 关于模的完全剩余系(关键词-数学方法)
    • ¥15 有没有人懂这个博图程序怎么写,还要跟SFB连接,真的不会,求帮助
    • ¥30 模拟电路 logisim
    • ¥15 PVE8.2.7无法成功使用a5000的vGPU,什么原因
    • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
    • ¥15 安装quartus II18.1时弹出此error,怎么解决?
    • ¥15 keil官网下载psn序列号在哪
    • ¥15 想用adb命令做一个通话软件,播放录音
    • ¥30 Pytorch深度学习服务器跑不通问题解决?