在下面的 python 中,我的代码正在解决这个问题,但是我在 Node.JS 中发现了这个请求模块的困难。
这是我的python代码:
inputData = {
"datasetName": "dataset44",
"typeOfDataset": "TS",
"userID": "c0fe211c_8c41_459a_9019_19d98111ed92"
}
fileName = 'out.csv'
files = {
'json': (None, json.dumps(inputData), 'application/json'),
'file': (os.path.basename(fileName), open(fileName, 'rb'),
'application/octet-stream')
}
我在这里尝试的是:
var fileData = fs.createReadStream(filePath);
var headers = {
'Content-Type': 'application/json , application/octet-
stream,
multipart / form - data ' }
var files = {
'json': {
"datasetName": dataSetName,
"typeOfDataSet": "TS",
"userID": req.session.userSourceID
},
'file': fileData
}
// Configure the request
var options = {
url: ' http://xx.xx.xx.x:x/x1/createx',
method: 'POST',
headers: headers,
json: files
}
request(options, function(error, response, body) {