Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 发送二进制文件_Node.js_Express_Mocha.js_Chai - Fatal编程技术网

Node.js 发送二进制文件

Node.js 发送二进制文件,node.js,express,mocha.js,chai,Node.js,Express,Mocha.js,Chai,我需要测试一个文件上传,不使用多部分表单数据 it('Create node', () => { return chai.request(server) .post('/api/sensornodes') .set('Content-Type', 'application/json') .send(fs.readFileSync('test/manifest/sensor_nodes.json')) .then((re

我需要测试一个文件上传,不使用多部分表单数据

it('Create node', () => {
    return chai.request(server)
        .post('/api/sensornodes')
        .set('Content-Type', 'application/json')
        .send(fs.readFileSync('test/manifest/sensor_nodes.json'))
        .then((res) => {
            expect(res.status).to.eql(204);
        });
});
这个测试调用下面的端点,在这里我使用主体解析器来解析请求

public create(req: Request, res: Response, next: NextFunction) {
    console.log("req body", req.body)
}
但是当我执行测试时,
req.body
是这样一个对象,不是我所期望的

{ 
    type: 'Buffer',
    data:
       [ 123,
         10,
         32,
         32,
         32,
         ...
       ]
}
当我通过Postman调用该端点时,一切都正常,在
req.body
中我有.json的内容


我哪里错了?

我缺少编码类型

我已经修好了

.send(fs.readFileSync('test/manifest/sensor\u nodes.json','utf8'))