InfaceMan
InfaceMan
2017-10-22 04:35

node服务端保存文件出错。

  • node.js
  • upload
  • express
  • fs
 var fs=require("fs");
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
router.post("/",multipartMiddleware,function(req,res,next){
   //var target_path = __dirname + '/upload/jj.jpg' ; //  F:\lianix\myapp_express\myapp\routes/upload/jj.jpg
   var target_path = __dirname + '\\upload\\jj.jpg' ;//F:\lianix\myapp_express\myapp\routes\upload\jj.jpg
   console.log(" req.files.file.path=",req.files.file.path);//有值 C:\Users\INFACE~1\AppData\Local\Temp\FJ1VimvUuj5XhUQaFTR8F3rm
   console.log("target_path===",target_path);
   fs.renameSync(req.files.file.path, target_path, function (err) {
      if (err) {
            console.log("出错了===",err);
      }
     console.log(" 成功");
   });
    res.send({"result":"1",msg:"成功"});
})

req.files.file.path 和 target_path 都有值。然后执行 fs.renameSync 方法 的时候报错。图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答