使用node.js上传文件(使用包panxapi)

时间:2015-02-24 05:57:51

标签: node.js

是否可以使用panxapi上传文件?

例如,API调用需要文件上传来设置user-ip mapping。

用curl完成这个

curl -form file=@myfile "https://hostname/api/?type=user-id&action=set"

我不确定如何使用panxapi将此参数作为参数添加到我的API调用中。

继承我的代码:

var panxapi = require('panxapi');

// Connect to the client
var client = panxapi.createPanClient({
    host: 'hostname',
    key: 'apikey',
    protocol: 'https'
});

var params = {
    type: 'user-id',
    action: 'set',
}

client.request(params, function(err, xml, etree) {
    if (err) console.log(err);
    console.log(xml);
})

卷曲调用(有效)

curl --form file=@ipmapping "https://hostname/api/?type=user-id&action=set&key=<key>"

1 个答案:

答案 0 :(得分:0)

通过向包添加功能来解决。分叉here