ENOENT: no such file or directory .?

后端 未结 14 1571
梦谈多话
梦谈多话 2020-12-09 17:15

This is error which am getting while post data and file. I have followed \'academind\' tutorial for building Restful API services, also i have been searching answer for this

14条回答
  •  天涯浪人
    2020-12-09 17:37

    Try the following:

    1. Require this as a constant (const path = require('path');)
    2. Change this line

      cb(null, './uploads/');

    With this:

    cb(null, path.join(__dirname, '/uploads/'));
    

    As I can see, you are trying to get a path that is not on served on the server, but rather a path that is on the server machine.

    UPDATE

    Try also changing this

    app.use('/uploads', express.static('uploads'));
    

    To this:

    app.use(express.static(__dirname));
    

    In order to expose the __dirname for static files.

提交回复
热议问题