-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attach file gives 400 bad request #111
Comments
Hey @coolnixy thanks for the issue. I believe the problem you're seeing is because The fix could be to try setting var file_path = '../data/invalid.csv';
chai.request(config.baseUrl)
.put(url)
.attach('file', fs.readFileSync(file_path))
.set('Accept', 'application/json')
.set('Content-Type', 'customHeader')
.end(function (err, res) {
res.should.have.status(500);
done();
}); |
Thanks @keithamus for your response. I tried your suggestion, but didn't work for me :( Any other way I can get this working? |
@coolnixy could you please provide more information, or perhaps write a reduced test case? If you |
@keithamus Thanks for responding.. I am getting message "The request is invalid" in result. What you mentioned on your first comment is correct. The custom header is not passed. Is there a way we can attach the file as binary and let the custom header be there? |
@coolnixy can you please provide the full output of res - I'm interested in seeing what the initial request headers were (which are attached to the res object). |
@keithamus here is the full output.. Upload claims tests Upload claims tests |
@coolnixy yeah see it is changing the request header's content type to The way to fix that should be overriding the header after |
Thanks @keithamus . I will try to override the header and see if it works. Will update you, if it works!! Thanks for your help thus far!. Appreciated. |
@coolnixy Gonna close this issue due to no updates in a few months. Please feel welcome to reopen it if there's still an issue! |
I am also facing a similar problem: https://stackoverflow.com/questions/46204374/chai-http-attach-sets-up-content-type-multipart-formdata chai.request('http://localhost:8085') Still when i log the request content type in the code i see req.contentType : multipart/form-data |
var file_path = '../data/invalid.csv';
chai.request(config.baseUrl)
.put(url)
.set('Accept', 'application/json')
.set('Content-Type', 'customHeader')
.attach('file', fs.readFileSync(file_path))
.end(function (err, res) {
res.should.have.status(500);
done();
});
I am expecting a 500 response (not here to argue, that's a good way to do things or not, it's a requirement, that I have to test) but I am getting 400
Testing the same manually (using POSTMAN) works just fine.
Any resolution will be highly appreciated. I am kinda blocked on this one..
The text was updated successfully, but these errors were encountered: