相关疑难解决方法(0)

上传文件并使用multer传递其他参数

我正在使用jQuery Form Pluginmulter将文件上传到我的服务器.这工作正常,但我试图传递一个额外的参数,这将确定文件的确切位置.

我有以下代码,我想扩展为行为如上所述:

HTML

<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)

客户端JS

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)

Node.js路由

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)

javascript file-upload jquery-forms-plugin node.js multer

6
推荐指数
1
解决办法
1万
查看次数