btw to output a status code and end response you'd do
res.writeHead(200);
res.end();
So now I am on the server and want to save the image in a file. So I
pipe the request stream into a writable file stream:
req.pipe(fileStream);
Everything works just fine except that the request is not ending and
therefore, I cannot open the written file because the file descriptor
is still open/hanging around. A GET request to the written file hangs
until that writable file stream is closed. This happens automatically
after 2 minutes.
But if I manually restart the server after the file was written (that
closes the file writable stream and the underlying open file
descriptor) the files can be requested through GET requests.
So, how can I force the request to close when it has been "consumes"?
The XMLHttpRequest POST requests have no "Connection: keep-alive"
headers. Is this considered default on the server is missing? (If this
plays any role)
Any other ideas that I should try?
Thanks!
xhr.setRequestHeader('Content-Length', file.fileSize);
Chrome thrown an error:
Refused to set unsafe header "Content-Length"
and no Content-Length is sent to the server.
Chrome shows me in Dev tools in the Network tab for my request:
Name Method Status Type
... POST (pending) image/jpeg
Make sure you're closing the XHR cleanly, too.
On Dec 3, 10:21 am, Gabriel Petrovay <gabipetro...@gmail.com> wrote:
> But as I see, content-length should be handled automatically:http://stackoverflow.com/questions/2623963/webkit-refused-to-set-unsa...
File: 92270
ReqL: 92270
It doesn't look like you're registering any error handlers. Are you
sure there are no errors?
--
Martin Cooper
> Thanks!
>
> Gabriel
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
req.on('error', function(err) { console.log(err);});
On Dec 3, 7:49 pm, Martin Cooper <mfncoo...@gmail.com> wrote:
I don't think a writable *file* stream will ever emit 'end', did you
try the 'close' event?
Having such an event I could call close() on the file stream. I put
the end event there to see if this gets somehow called. But it
doesn't. So that was just a debug trial.
@Liam:
I did not try it through the form. First because I am doing it do it
from the XMLHttpRequest where I want to keep it light. And on the
server, if I post it through a form that it will go through another
path (bodyParser and request parameters). Or is there a streaming
scenario when using forms?
Minimizing the problem and writing it back I discovered one leak: the
request was not terminating because the uploadImage (http://
codepad.org/DEbxFWyD ) was wrapped in one more function (adding some
entries in the DB). That was the problem because this wrapper was not
properly calling it's callback function and therefore uploadImage's
callback was not bring called.
But that still leaves me with this weird behavior:
1. Now the image is uploaded and saved and the POST requests finished
with 200
2. But the 1st request to node after this POST hangs (pending...). It
doesn't matter what the GET request is (a static file, a route, or a
non-exitent 404 URL)
If I reload this 1st request it loads properly. Where could the
problem be here?
PS: thanks for having me solve the first issue by minimizing and
rewriting that piece of code.
app.on('request', function(request) {
console.log(request.url);
});
app.on('connection', function() {
console.log('connection');
});
How can I go deeper to see why nodejs is not receiving this request?
I loaded the 1st URL after the POST with curl and with a 2nd browser
and it works OK. Also the same hanging behavior in the 2nd browser, so
its most probably my bug. Something in the client code (http://
codepad.org/hPv38KxZ) is not properly handling the XMLHttpRequest.
Thanks again! (I'll be back once I find the problem)
https://github.com/joyent/node/issues/2263