var form = {
widgetReleaseId: req.body.widgetReleaseId,
version: req.body.version,
uploadDate: req.body.uploadDate,
myfiles : myfiles
};
以下是 npm 请求。
request.post(
{
url:target_url+'widget-releases/',
formData:form
}, function optionalCallback(err, httpResponse, body) {
console.log('body'+body)
if (err) {
console.log(err)
}
del(['uploads/'+req.session.loginuser+'**/*'], function (err, paths) {
console.log('Deleted files/folders:\n', paths.join('\n'));
});
res.redirect('/admin-ui/widget-release/add');
});
Api 在另一个 nodejs 服务器上公开了“发布”。.从应该使用 multer 创建的文件夹中读取文件时出现错误。由于 req.body.widgetReleaseId 是 'undefined' ,它没有创建文件夹来复制文件
router.post('/',multer({
dest: './public/api/downloads/',
changeDest: function(dest, req, res) {
dest += req.body.widgetReleaseId;
var stat = null;
try {
stat = fs.statSync(dest);
} catch (err) {
mkdirp.sync(dest);
}
if (stat && !stat.isDirectory()) {
throw new Error('Directory cannot be created because an inode of a different type exists at "' + dest + '"');
}
return dest;
},
rename: function(fieldname, filename, req,res){
return filename.replace(/\W+/g, '-');
},
onFileUploadStart: function (file, req, res) {
console.log(file.fieldname + ' is starting ...')
},
onFileUploadComplete: function (file, req, res) {
console.log(file.fieldname + ' uploaded to ' + file.path)
} ,
onError: function (error, next) {
console.log(error)
next(error)
}
}), function(req,res) {
//code goes here..
fs.readdir('./public/api/downloads/'+req.body.widgetReleaseId,function(err,files ){
....
});
正文解析器设置正确且在任何路由之前。几天前它还在工作,但现在出现错误:ENOENT 错误,因为没有数据通过 formData 进入 nodejs 服务器。有什么线索吗?我已经清理了缓存并更新了项目。