Created
February 4, 2012 07:31
-
-
Save craigyk/1736167 to your computer and use it in GitHub Desktop.
http ServerRequest data loss?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.put '/uploads/:fileid', (request,response) -> | |
getCachePath (path) -> #... does a bunch of prep | |
stream = fs.createWriteStream path, | |
bufferSize: 1024*1024*4 | |
encoding: 'binary' | |
start: start | |
flags: if start != 0 then 'r+' else 'w' | |
stream.on 'close', -> | |
response.send 202, | |
'Access-Control-Allow-Origin' : '*' | |
request.pipe stream | |
# first chunk of data never gets piped | |
# as an experiment I tried setting a data handler earlier. | |
# the following emits a console message that the data is getting received | |
# so compared to the above, it is getting lost somewhere between | |
app.put '/uploads/:fileid', (request,response) -> | |
request.on 'data', (data) -> | |
console.log 'received:',data.length | |
getCachePath (path) -> #... does a bunch of prep | |
stream = fs.createWriteStream path, | |
bufferSize: 1024*1024*4 | |
encoding: 'binary' | |
start: start | |
flags: if start != 0 then 'r+' else 'w' | |
stream.on 'close', -> | |
response.send 202, | |
'Access-Control-Allow-Origin' : '*' | |
request.pipe stream | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment