我正在使用jQuery Form Plugin和multer将文件上传到我的服务器.这工作正常,但我试图传递一个额外的参数,这将确定文件的确切位置.
我有以下代码,我想扩展为行为如上所述:
<form id="uploadForm"
enctype="multipart/form-data"
action="/files"
method="post">
<input type="file" id="userFile" name="userFile"/>
<input type="text" hidden id="savePath" name="savePath" value="path"/>
</form>
Run Code Online (Sandbox Code Playgroud)
uploadForm.submit(function() {
$(this).ajaxSubmit({
error: function(xhr) {
console.log('Error: ' + xhr.status);
},
success: function(response) {
console.log('Success: ' + response);
}
});
return false;
});
Run Code Online (Sandbox Code Playgroud)
app.post(APIpath + "file",function(req,res){
var storage = multer.diskStorage({
destination: absoluteServePath+ "/" + config.filePath,
filename: function (req, file, cb) {
cb(null, file.originalname);
}
});
var upload = multer({ storage : storage}).any();
upload(req,res,function(err) …Run Code Online (Sandbox Code Playgroud)