0
我打算用NodeJs上傳文件,這裏是我的代碼。在nodejs中上傳文件
app.post('/upload',urlencodedParser, function(req, res) {
if (!req.files)
return res.status(400).send('No files were uploaded.');
// The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
var sampleFile = req.files.sampleFile;
// Use the mv() method to place the file somewhere on your server
sampleFile.mv(__dirname + '/upload', function(err) {
if (err)
return res.status(500).send(err);
console.log('File uploaded!');
});});
問題是我得到那個錯誤。
/path_of_my_pc/node_modules/fileupload/lib/modules/file.js:23
throw error
^
錯誤:EACCES:許可被拒絕,MKDIR '/上傳' 在錯誤(原生)
的文件,其中的所有代碼,都允許。
我使用'express-fileupload'並且工作得很好。 – erevos13