先看图:

Error: ENOENT: no such file or directory, open 'E:\Program Files\nodejs\tmp\upload_38b32f25bc984333c

出现这种问题的主要原因是你要上传的文件没有在同一个目录夹里

所以要把文件夹tmp和运行的js文件放在同一个目录里,如下图:

Error: ENOENT: no such file or directory, open 'E:\Program Files\nodejs\tmp\upload_38b32f25bc984333c

然后是改路径,刚开始是我写的路径是fs.readFile("/tmp/test.png"...) 要把"/tmp/test.png",改成"./tmp/test.png"就没有问题了

  fs.readFile("./tmp/test.png", "binary", function(error, file){
        if(error){
             response.writeHead(500,{"Content-Type":"text/plain"});
             response.write(error + "\n");
             response.end();
        }else{
             response.writeHead(200,{"Content-Type":"image/png"});
             response.write(file,"binary");
             response.end();
        }
    });

相关文章:

  • 2021-06-04
  • 2021-07-17
  • 2022-03-06
  • 2021-07-30
  • 2022-12-23
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-28
  • 2021-12-17
  • 2021-11-11
  • 2021-04-20
  • 2021-12-02
相关资源
相似解决方案