示例:

API封装文档
net
const fs = require('fs');

var httpClient = new @.net.httpClient();

httpClient.multipartRequest("http://127.0.0.1/file-upload", {
    data: {
        "body": {
            "usrname": ["yaya", "test"],
            "userdata": "this"
        },
        "files": {
            "file": {
                "data": fs.createReadStream('./test 中文2.txt')
            },
            "otherFiles": [{
                "data": new Buffer("123"),
                "filename": "1.txt"
            },{
                "data": "测试文字",
                "filename": "testFile",
                "contentType": "text/plain"
            }]
        }
    },
        onSuccess: function() {
            @dump("upload successed");
        }
})

上述代码相当于提交

<form action="http://127.0.0.1/file-upload"
      enctype="multipart/form-data"
      method="post">
    <INPUT type="text" name="usrname"><!--填写yaya-->
    <INPUT type="text" name="usrname"><!--填写test-->
    <INPUT type="text" name="userdata"><!--填写this-->
    <INPUT type="file" name="file"><!--选择./test 中文2.txt文件-->
    <INPUT multiple="multiple" type="file" name="file"><!--选择内容为123的1.txt文件与testFile文件-->
</form>

最后更新时间:2018年11月7日 11:12:08