Exception 为什么使用nodejs上传异常

Exception 为什么使用nodejs上传异常,exception,node.js,Exception,Node.js,代码 form.parse(request, function(error, fields, files) { console.log('parsing done'); fs.renameSync(files.upload.path, 'c:/tmp/test.png'); response.writeHead(200, {'Content-Type': 'text/html'}); response.write('received image:<br/&

代码

form.parse(request, function(error, fields, files) {
    console.log('parsing done');

    fs.renameSync(files.upload.path, 'c:/tmp/test.png');
    response.writeHead(200, {'Content-Type': 'text/html'});
    response.write('received image:<br/>');
    response.write('<img src="/show" />');
    response.end();
});
form.parse(请求、函数(错误、字段、文件){
log(“解析完成”);
重命名同步(files.upload.path,'c:/tmp/test.png');
writeHead(200,{'Content-Type':'text/html'});
write('接收到的图像:
'); 回答。写(“”); response.end(); });

异常信息

返回binding.rename(pathModule.\u makeLong(oldPath))

错误:enoint,没有这样的文件或目录'C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\esdafdace32323432a3f'
在Object.renameSync(fs.js:330:18)

这是因为
其他
renameSync
不会创建新文件夹,因此您应该确保
tmp/
必须存在。 您需要在sourcecode文件夹中创建tmp文件夹,然后设置
uploadDir
,如下所示:

var form = new formidable.IncomingForm();
  form.uploadDir = "tmp";
  console.log("about to parse");
  form.parse(request, function(error, fields, files) {
    console.log(files.upload.path);
    try{
        fs.renameSync(files.upload.path, "tmp/test.jpg");
    }catch(e){
        console.log(e);
    }
    response.writeHead(200, {"Content-Type": "text/html"});
    response.write("received image:<br/>");
    response.write("<img src='/show' />");
    response.end();
  });
var form=new.IncomingForm();
form.uploadDir=“tmp”;
log(“即将解析”);
解析(请求、函数(错误、字段、文件){
console.log(files.upload.path);
试一试{
重命名同步(files.upload.path,“tmp/test.jpg”);
}捕获(e){
控制台日志(e);
}
writeHead(200,{“内容类型”:“text/html”});
响应。写入(“接收到的图像:
”); 回答。写(“”); response.end(); });
这是因为
其他
renameSync
不会创建新文件夹,因此您应该确保
tmp/
必须存在。 您需要在sourcecode文件夹中创建tmp文件夹,然后设置
uploadDir
,如下所示:

var form = new formidable.IncomingForm();
  form.uploadDir = "tmp";
  console.log("about to parse");
  form.parse(request, function(error, fields, files) {
    console.log(files.upload.path);
    try{
        fs.renameSync(files.upload.path, "tmp/test.jpg");
    }catch(e){
        console.log(e);
    }
    response.writeHead(200, {"Content-Type": "text/html"});
    response.write("received image:<br/>");
    response.write("<img src='/show' />");
    response.end();
  });
var form=new.IncomingForm();
form.uploadDir=“tmp”;
log(“即将解析”);
解析(请求、函数(错误、字段、文件){
console.log(files.upload.path);
试一试{
重命名同步(files.upload.path,“tmp/test.jpg”);
}捕获(e){
控制台日志(e);
}
writeHead(200,{“内容类型”:“text/html”});
响应。写入(“接收到的图像:
”); 回答。写(“”); response.end(); });
重命名不会创建新文件夹
谢谢!解决了我的问题<代码>重命名不会创建新文件夹
谢谢!解决了我的问题!