chai-http/superagent : set Content-Type of mulipar

2019-07-20 03:00发布

问题:

Uploading a file in an integration test as follows:

chai.request(server.instance)
            .post('/profile/photo/0')
            .set('Access-Token', accessToken)
            .set('API-Key', testConfig.apiKey)
            .set('Content-Type', 'image/png')
            .field({contentId: 'foobar'})
            .attach('file', fs.readFileSync(__dirname + '/file.png'), 'file')
            .end((err, res) => {
                console.log(JSON.stringify(res.body))
                res.should.have.status(200)
                done()
            })

The content type of the multipart file is: application/octet-stream and I need it to be image/png. How can I set that?