Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream ended unexpectedly #25

Closed
d1b1 opened this issue Jan 31, 2013 · 5 comments
Closed

stream ended unexpectedly #25

d1b1 opened this issue Jan 31, 2013 · 5 comments

Comments

@d1b1
Copy link

d1b1 commented Jan 31, 2013

I am running into a very hard to diagnose bug. When I try to use the file upload feature in this module it work for some requests and not for others. Hard to trace down. Is there something obvious? The API I am talking to is build using node, express and swagger.

Bug from REQUEST:

Error: MultipartParser.end(): stream ended unexpectedly: state = PART_DATA_START
at MultipartParser.end (/Users/steve/Dropbox/github/RandD/api.formagg.io/node_modules/express/node_modules/connect/node_modules/formidable/lib/multipart_parser.js:306:12)
at IncomingMessage.IncomingForm.parse.fields (/Users/steve/Dropbox/github/RandD/api.formagg.io/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js:102:30)
at IncomingMessage.EventEmitter.emit (events.js:85:17)
at IncomingMessage._emitEnd (http.js:366:10)
at HTTPParser.parserOnMessageComplete as onMessageComplete
at Socket.socket.ondata (http.js:1690:22)
at TCP.onread (net.js:402:27)

Code:
var FormData = require('form-data')
var http = require('http');
var fs = require('fs')

var form = new FormData();
form.append('name', data.name || '');
form.append('address', data.address || '');
form.append('city', data.city || '');
form.append('state', data.state || '');
form.append('zipcode', data.zipcode || '');
form.append('email', data.email || '');
form.append('country', data.country || '');
form.append('website', data.website || '');
form.append('type', data.type || '');
form.append('description', data.description || '');
form.append('logofile', fs.createReadStream(req.files.logofile.path));

var request = http.request({
method: 'PUT',
host: 'formaggio.dev',
port: 4001,
path: '/maker/' + id + '?api_key=guest-key',
headers: form.getHeaders()
});

form.pipe(request);
request.on('response', function(requestres) {
if (requestres.statuscode == 500) {
//res.send(requestres);
} else {
res.redirect('/maker/' + id + '/detail');
}
});

request.on('error', function(err) {
console.log('Got an eror');
})

@d1b1
Copy link
Author

d1b1 commented Feb 1, 2013

I found a work around. It seems that form.append() will result in an invalid header or response size if the appended value is an empty string ( '' ). I have tested this a big and found that using a single space work. But hacky, but good for now.

@celer
Copy link

celer commented Feb 8, 2013

Hi,

This bug is due an issue with node-combined-stream, specifically issue number 4

felixge/node-combined-stream#4

But now the problem is that node-form-data specifies a fixed version of node-combined-stream - 0.0.3 it really should be ~0.0.4

So node-form-data needs to have its dependencies modified to ask for a later version of node-combined-stream specifically 0.0.4.

Thanks,

celer

@celer
Copy link

celer commented Feb 10, 2013

I have fixed the issue in node-form-data, so we are closer, but now the issue is that request specifies form-data in bundleDependencies in package.json, so it will never get an updated version of node-form-data, I will file an issue against request and link it to this issue.

@celer
Copy link

celer commented Feb 10, 2013

I've opened the following issue in request: request/request#431

In the mean time you can specify the following in your package.json as a dependency:

In package.json

"dependencies": {
    "request": "git://github.com/celer/request.git",
}

@alexindigo
Copy link
Member

@celer Issue request/request/pull/431 has been closed, so I assume we're good to go.
Please let me know if something else left to be done. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants