joepie91 / node-bhttp

A sane HTTP client library for Node.js with Streams2 support.
62 stars 12 forks source link

fails silently when an array provided as part of a multipart form upload #33

Closed taemon1337 closed 7 years ago

taemon1337 commented 7 years ago
Promise.try(function() {
  return bhttp.post("/upload", { tags: ['one','two','three'], file: fs.createReadStream('/test.txt') }, { forceMultipart: true });
}).then(function(resp) {
  console.log("Response: ", err);
}).catch(function(err) {
  console.log("Error: ", err);
});

The request fails without any console log message.

joepie91 commented 7 years ago

The request fails

Can you clarify what you mean with this? I've tried to reproduce locally with the following code (modifying the URL and the test.txt path):

var Promise = require("bluebird");
var bhttp = require("bhttp");
var fs = require("fs");

Promise.try(function() {
  return bhttp.post("http://localhost:5000/upload", { tags: ['one','two','three'], file: fs.createReadStream('./test.txt') }, { forceMultipart: true });
}).then(function(resp) {
  console.log("Response: ", err);
}).catch(function(err) {
  console.log("Error: ", err);
});

... and the request is sent successfully and correctly:

POST /upload HTTP/1.1
user-agent: bhttp/1.2.4
content-length: 570
content-type: multipart/form-data; boundary=----1534fc32-7532-49cb-9c9e-a5af8595d7d6
Host: localhost:5000
Connection: close

------1534fc32-7532-49cb-9c9e-a5af8595d7d6
Content-Disposition: form-data; name="tags[]"
Content-Type: text/plain

one
------1534fc32-7532-49cb-9c9e-a5af8595d7d6
Content-Disposition: form-data; name="tags[]"
Content-Type: text/plain

two
------1534fc32-7532-49cb-9c9e-a5af8595d7d6
Content-Disposition: form-data; name="tags[]"
Content-Type: text/plain

three
------1534fc32-7532-49cb-9c9e-a5af8595d7d6
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

foo
bar
baz

------1534fc32-7532-49cb-9c9e-a5af8595d7d6--
taemon1337 commented 7 years ago

Sorry for the trouble, I was able to work around the issue I had (which must have been with the server side code); the request was timing out from either the client or server. Either way, I've gotten mine working now and lost the code which doesn't work, so thanks anyway.