question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Manually set content-type when using .attach

See original GitHub issue

Hey! I’m sending a request like this

request
    .post('http://website.com/upload')
    .attach('image', path)
    .send(payload)
    .set('content-type', 'multipart/form-data; boundary=----WebKitFormBoundaryKWf3FhTklvtPkprk')

However, the content-type gets overridden by superagents own value. Resulting in a res.req._headers like this

content-type': 'multipart/form-data; boundary=--------------------------442535245526379898253153

Is there any way i can force set the content-type manually?

Or perhaps figure out superagents content-type pre-post so i can use the same boundary in my .send(payload)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kornelskicommented, Jan 10, 2017

You can’t use attach() and send() at the same time. You can either use your own content-type and your own payload with .send().set() OR you can let all of it being 100% auto-generated by the browser by using .attach().field(). They don’t mix.

0reactions
kornelskicommented, Jan 11, 2017

Please make a new issue for the other problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Manually set content-type when using .attach #1152 - GitHub
Hey! I'm sending a request like this request .post('http://website.com/upload') .attach('image', path) .send(payload) .set('content-type', ...
Read more >
How do you set the Content-Type header for an HttpClient ...
I tried creating a new StringContent with the three parameters and it didn't work. I then manually: request.Content.Headers.Remove("Content-Type") and then: ...
Read more >
Content-Type - HTTP - MDN Web Docs - Mozilla
In responses, a Content-Type header provides the client with the actual content type of the returned content. This header's value may be ...
Read more >
Solved: Update Content-Type in Attachment before submissio...
hello, I have set resource root as ${projectDir} and i am not attaching files manually and using groovy script instead. And i've tried ......
Read more >
How to add Content-Type for income request by conditions ...
Put a separate MPGW in front of this one, which only sets the Content-Type header as needed, then sends the request to your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found