Skip to content
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

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

Open
Krzeminska opened this issue Dec 11, 2019 · 4 comments
Open

Comments

@Krzeminska
Copy link

Krzeminska commented Dec 11, 2019

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

@Krzeminska
Copy link
Author

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

  • .attach('file', fs.readFileSync(file_path))
  • .field()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants