{"action":"created","issue":{"url":"https://api.github.com/repos/request/request/issues/2499","repository_url":"https://api.github.com/repos/request/request","labels_url":"https://api.github.com/repos/request/request/issues/2499/labels{/name}","comments_url":"https://api.github.com/repos/request/request/issues/2499/comments","events_url":"https://api.github.com/repos/request/request/issues/2499/events","html_url":"https://github.com/request/request/issues/2499","id":197920492,"number":2499,"title":"File upload works only with standard read streams","user":{"login":"ovk","id":693072,"avatar_url":"https://avatars.githubusercontent.com/u/693072?v=3","gravatar_id":"","url":"https://api.github.com/users/ovk","html_url":"https://github.com/ovk","followers_url":"https://api.github.com/users/ovk/followers","following_url":"https://api.github.com/users/ovk/following{/other_user}","gists_url":"https://api.github.com/users/ovk/gists{/gist_id}","starred_url":"https://api.github.com/users/ovk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ovk/subscriptions","organizations_url":"https://api.github.com/users/ovk/orgs","repos_url":"https://api.github.com/users/ovk/repos","events_url":"https://api.github.com/users/ovk/events{/privacy}","received_events_url":"https://api.github.com/users/ovk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-12-28T21:43:26Z","updated_at":"2017-01-16T15:00:02Z","closed_at":null,"body":"I've been trying to upload a file (using multipart POST request) that is inside TAR archive (I use `tar-stream` library to get stream to a particular file inside TAR archive). But it always fails with ECONNRESET error. After a bit of experimenting it seems like it can only upload streams constructed directly with `fs.createReadStream` and fails with irrelevant error for all other streams. \r\n\r\nHere's a minimal example to reproduce problem. If `PassThrough` stream is passed into `formData` then the following error is occurred:\r\n\r\n```\r\nERROR { Error: socket hang up\r\n    at createHangUpError (_http_client.js:254:15)\r\n    at Socket.socketOnEnd (_http_client.js:346:23)\r\n    at emitNone (events.js:91:20)\r\n    at Socket.emit (events.js:185:7)\r\n    at endReadableNT (_stream_readable.js:974:12)\r\n    at _combinedTickCallback (internal/process/next_tick.js:74:11)\r\n    at process._tickCallback (internal/process/next_tick.js:98:9) code: 'ECONNRESET' }\r\n```\r\n\r\nServer:\r\n```JavaScript\r\nvar http = require('http');\r\n\r\nhttp.createServer(function (request, response) {                                                                                    \r\n\trequest.on('data', function(chunk) {\r\n      console.log(chunk.length);\r\n    });    \r\n    request.on('end', function() {\r\n      response.writeHead(200, \"OK\", {'Content-Type': 'text/html'});\r\n      response.end();\r\n    });                                                           \r\n}).listen(8077);\r\n```\r\n\r\nClient:\r\n```JavaScript\r\nvar request = require('request');\r\nvar fs = require('fs');\r\nvar PassThrough = require('stream').PassThrough;\r\n\r\nvar rs = fs.createReadStream('some_file.bin'), pt = new PassThrough();\t\r\nrs.pipe(pt);\t\r\nrequest({\r\n\t'method': 'POST',\r\n\t'url': 'http://127.0.0.1:8077',\r\n\t'formData':\t{\r\n\t\t'uploaded_file': pt\r\n\t}\r\n}, function (err, httpResponse, body)\r\n{\r\n\tif (err)\r\n\t\tconsole.log('ERROR', err);\r\n\telse\r\n\t\tconsole.log({ 'statusCode': httpResponse.statusCode, 'body': body });\r\n});\r\n```"},"comment":{"url":"https://api.github.com/repos/request/request/issues/comments/272884444","html_url":"https://github.com/request/request/issues/2499#issuecomment-272884444","issue_url":"https://api.github.com/repos/request/request/issues/2499","id":272884444,"user":{"login":"philipp-spiess","id":458591,"avatar_url":"https://avatars.githubusercontent.com/u/458591?v=3","gravatar_id":"","url":"https://api.github.com/users/philipp-spiess","html_url":"https://github.com/philipp-spiess","followers_url":"https://api.github.com/users/philipp-spiess/followers","following_url":"https://api.github.com/users/philipp-spiess/following{/other_user}","gists_url":"https://api.github.com/users/philipp-spiess/gists{/gist_id}","starred_url":"https://api.github.com/users/philipp-spiess/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philipp-spiess/subscriptions","organizations_url":"https://api.github.com/users/philipp-spiess/orgs","repos_url":"https://api.github.com/users/philipp-spiess/repos","events_url":"https://api.github.com/users/philipp-spiess/events{/privacy}","received_events_url":"https://api.github.com/users/philipp-spiess/received_events","type":"User","site_admin":false},"created_at":"2017-01-16T15:00:02Z","updated_at":"2017-01-16T15:00:02Z","body":"@PierreCavalet Is your buffer already encoded text? For me the buffer happens to be a binary blob which broke the encoding of the request (since it was apparently not properly encoded)."}}
{"actor":{"display_login":"philipp-spiess"}}