• I think:

        f.pipe(res,{chunkSize:4096,end:true,comp­lete:res.end()}); 
    

    Is the problem, and would explain Uncaught Error: Expecting a function to call, got Number

    What happens is by typing res.end() you are executing res.end right then and setting complete to what it returns (which is almost certainly not a function). What you want is:

       f.pipe(res,{chunkSize:4096,end:true,comp­lete:function() {res.end()}}); 
    

    It sounds like you weren't actually doing that at the time - but maybe you're doing something very similar somewhere else.

    Definitely calling res.end() seems like a bad idea to me - that'll try and close the connection, which would mean that it's unlikely any posted data would get read.

    Is the chunkSize the file length?

    No, this should be the maximum size of a chunk of data that is sent down the pipe each time data is available. (Pipe effectively reads chunkSize bytes from the source and then writes them to the destination whenever data is available)

    The res.end() worked, what about closing the file after the Pipe finishes?

    Maybe do it when the connection itself closes, on res.on('close', ...)?

About

Avatar for Gordon @Gordon started