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.

making post with multipart/form content-type

See original GitHub issue

What is the correct way to set the headers/body to be able to make a post request with a multipart/form content-type? I can’t figure out where these should go (or where to put them):

----Z7depKeH0iSSjand
Content-Disposition: form-data; name="file"; filename="test.csv"
Content-Type: text/csv

----Z7depKeH0iSSjand
Content-Disposition: form-data; name="filename"

test.csv
----Z7depKeH0iSSjand

This is what I currently have:

    const csv = makeRequest(); // does a GET, stores the csv from that response into a buffer 
    const opts = {
      headers: {
        'Content-Type': 'multipart/form-data; boundary=----Z7depKeH0iSSjand',
        'Accept-Encoding': 'multipart/form-data',
        'X-AUTH-TOKEN': authToken,
      },
      body: csv,
    }
    request('POST', url, opts)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ForbesLindesaycommented, Oct 23, 2015

Excellent, that’s exactly the right use case for this library. I am also working on supporting synchronous multi-part form upload so that should be here soon.

0reactions
adiGitUsercommented, Jan 23, 2021

Hey @ForbesLindesay can you please help - I still get 415 error on this request -

const request = require(‘sync-request’) const FormData = request.FormData;

	let form1 = new FormData()
        form1.append('grant_type', '*****')
		form1.append('username', '******')
		form1.append('password', '******')
		let res = request('POST', 'https://********healthsuite.com/authorize/oauth2/token', {
		  headers: this.getAppHeaders(), form :form1
		})
		console.log(res)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Send Data by Using a POST Method - Micro Focus
In the multipart/form-data content type, the HTTP message body is divided into parts, each containing a discrete section of data. Each message part...
Read more >
POST - HTTP - MDN Web Docs
The HTTP POST method sends data to the server. The type of the body of the request is indicated by the Content-Type header....
Read more >
application/x-www-form-urlencoded or multipart/form-data?
The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.
Read more >
Multipart formposts - Everything curl
A multipart formpost is what an HTTP client sends when an HTML form is submitted with enctype set to "multipart/form-data". It is an...
Read more >
HTTP- Understanding multipart/form-data content-type
In HTTP context, the multipart/form-data content-type is used for submitting HTML form. In the case of multipart/form-data, ...
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