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.

Why doesn't the request body look 'normal'?

See original GitHub issue

My form code:

var form = new FormData();

form.append(project.name+'.zip', fs.createReadStream("/"+project.name+'.zip'));
form.submit({
    host: 'http://host.mysite.dev',
    path: '/api/v1/prototypes',
    headers: {
      'Authentication': 'secret'
    }
  }, function(err, res) {
    if(err) console.log("ERR: ", err)
    else console.log("RES: ", res)
    console.log(res.statusCode);
  });

My backend is expecting the request to look like this (tested with postman).

------WebKitFormBoundarywo69VE86H8vMc9ah
Content-Disposition: form-data; name="attachment"; filename="basic.zip"
Content-Type: application/zip


------WebKitFormBoundarywo69VE86H8vMc9ah--

Instead, my request looks like this crazyness which rails can’t interpret as a file. I have no idea how to make a normal multipart form request with node.

{
"attachment":{
  "_overheadLength":157,
  "_valueLength":0,
  "_lengthRetrievers":[
     null
  ],
  "writable":false,
  "readable":true,
  "dataSize":0,
  "maxDataSize":2097152,
  "pauseStreams":true,
  "_released":false,
  "_streams":[
     "----------------------------860185489573893683941879\r\nContent-Disposition: form-data; name=\"app.zip\"; filename=\"app.zip\"\r\nContent-Type: application-zip\r\n\r\n",
   {
        "source":{
           "_readableState":{
              "objectMode":false,
              "highWaterMark":65536,
              "buffer":[
                 {
                    "type":"Buffer",
                    "data":[
                       80,
                       181
                    ]
                 }
              ],
              "length":65536,
              "pipes":null,
              "pipesCount":0,
              "flowing":false,
              "ended":false,
              "endEmitted":false,
              "reading":false,
              "sync":false,
              "needReadable":false,
              "emittedReadable":true,
              "readableListening":false,
              "defaultEncoding":"utf8",
              "ranOut":false,
              "awaitDrain":0,
              "readingMore":false,
              "decoder":null,
              "encoding":null
           },
           "readable":true,
           "domain":null,
           "_events":{

           },
           "_eventsCount":3,
           "path":"/Users/guest/Library/Application Support/foundation-apps-template/app.zip",
           "fd":299,
           "flags":"r",
           "mode":438,
           "autoClose":true
        },
        "dataSize":0,
        "maxDataSize":null,
        "pauseStream":true,
        "_maxDataSizeExceeded":false,
        "_released":false,
        "_bufferedEvents":[

        ],
        "_events":{

        },
        "_eventsCount":1
     },
     null
  ],
  "_currentStream":null,
  "_boundary":"--------------------------860185489573893683941879"
 }
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
farantesrodriguescommented, Oct 26, 2016

Hi guys, I bumped into this discussion while debugging an integration with Tableau REST API. I also was expecting to see a text body request instead of a stream. I fear this is what might be causing my request not to be accepted in the API (all rest seems to be formatted fine). Is there anyway we can avoid using stream/buffers to chunk the data being passed in the request ?

0reactions
alexindigocommented, Oct 22, 2015

Yep.

@erikmellum feel free to add more details and reopen the issue if you want to continue this discussion. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request Body - FastAPI
A request body is data sent by the client to your API. A response body is the data your API sends to the...
Read more >
Can't figure out how to replace the request body #1601 - GitHub
Describe the bug Trying to replace the request body is something that is not officially supported but should be possible. See #1473 ...
Read more >
Request bodies in GET requests - Evert Pot
Yes. In other words, any HTTP request message is allowed to contain a message body, and thus must parse messages with that in...
Read more >
Should you send a payload in an HTTP GET request? - LinkedIn
It is a common myth that we could not pass the request body in the HTTP GET request. HTTP 1.1 specification neither enforces...
Read more >
HTTP Request Body and HTTP Response Body - YouTube
HTTP Protocol Explained in this video. Understanding http request body and http response body is not an easy thing. But this is the...
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