2015-01-17 59 views
0

我只是想上傳和保存圖像在我public/images文件夾中,我得到文件的詳細信息通過req.files,在那之後我收到此類型的Error: EXDEV, rename 'c:\Users\abdul\AppData\Local\Temp\3348-qiy7kl.jpg'上傳的圖片不是在目標路徑保存在Node.js的

這裏是我的stuff

app.post('/upload',function(req,res){ 
    var tmp_path = req.files.file.path; 
    var target_path = './public/images/' + req.files.file.originalFilename; 
    fs.rename(tmp_path, target_path, function(err) { 
     if (err) throw err; 
     fs.unlink(tmp_path, function() { 
      if (err) throw err; 
      res.send('File uploaded to: ' + target_path + ' - ' + req.files.file.size + ' bytes'); 
     }); 
    }); 
    }) 
}; 

任何機構可以給任何建議或給我任何的參考,這樣我可以處理它?

回答

0

試試這個

console.log("File Name " + req.files.file.name); 
    console.log("File Path " + req.files.file.path); 

    fs.readFile(req.files.file.path, function (err, data) { 
     var newPath = "public/images/" + req.files.file.originalFilename; 
     console.log(newPath); 
     /// write file to uploads/fullsize folder 
     fs.writeFile(newPath, data, function (err) { 
      /// let's see it 
     }); 
+0

哎@Ali感謝,這對我的作品 – abdulbarik

相關問題