2016-08-03 55 views
0

我有一個代碼:的fs readFilesync錯誤路徑必須是上傳文件 這裏的代碼串

  var oriPath = JSON.stringify(req.files.profilePicture); 
      var data = fs.readFileSync(oriPath.path); 
      var ext = path.extname(oriPath.name); 
      if (!ext) { 
       return next(err); 
      } 

      var newName = Date.now().toString() + ext; 
      var path = config.fullhostname + config.uploadDir + newName; 
      if (!fs.writeFileSync(path, data)) { 
       return next("Failed to upload image", 400) 
      } 

和示值誤差這樣的:uncaughtException TypeError: path must be a stringvar data = fs.readFileSync(oriPath.path);

但文件表被成功上傳,如何解決這個問題?謝謝

回答

0

試圖迫使字符串轉換:

var data = fs.readFileSync(String(oriPath.path)) 
相關問題