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

先看图:

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

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

然后是改路径,刚开始是我写的路径是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();
        }
    });

猜你喜欢

转载自blog.csdn.net/Jackson23333/article/details/81303892