chaijs / chai-http

HTTP Response assertions for the Chai Assertion Library.
http://chaijs.com/plugins/chai-http
633 stars 113 forks source link

Status 400 when i try to attach multipart pdf files type form data #264

Open Krzeminska opened 4 years ago

Krzeminska commented 4 years ago

I'm trying to ask in this way:

request.post('/properUrl')
                .set('Content-Type', 'multipart/form-data')
                .set('Accept', 'application/json')
                .attach('file', './files/test.pdf', 'test.pdf')
                .type('formData')
                .then((response) => {
                    expect(response).to.have.status(200);
                })

I tried also with sending type of data in field: .field('type', 'formData') and the server say's, it's not proper way (responses with 400). Curl of proper request is:

curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json'  {"type":"formData"} '/properUrl'

Anyone knows what happen?

austince commented 4 years ago

Hey @Krzeminska, thanks for the issue! I'm not sure off the top of my head, but I would suggest looking at the superagent API to see if there's an answer there? If you are still having trouble, let me know and I'll see if I can reproduce. Do you control the other server/ can you see what the incoming request looks like?

Krzeminska commented 4 years ago

Yes, i was on this page, and tried to fix it with using its examples. Doesn't work with my issue. On server side i see nothing, because it could not parse header, so do not enter to the method (So i cannot debug it).

austince commented 4 years ago

Ok, no worries. Do any of these issues help?

Krzeminska commented 4 years ago

Yes, I tried, as this issues mention, using: