Created
June 9, 2014 13:17
-
-
Save scaleupcto/8a315eb13c652f2db7ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var http = require('http'); | |
app.get('/my/tn/upload/endpoint',function(req,res) { | |
var depotJSON = null; | |
var depotRequest = http.createRequest(depotOptions,function(depotResponse) { | |
var str = ""; // this will be the return body from DEPOT | |
depotResp.on('data', function(chunk){ | |
str += chunk; | |
}); | |
depotResp.on('end', function(){ | |
depotJSON = SON.parse(str)); | |
}); | |
}) | |
var form = new multiparty.Form(); | |
form.parse(req, function(err, fields, files) { | |
res.writeHead(200, {'content-type': 'text/plain'}); | |
res.write(depotJSON); // json response from Depot | |
res.end(util.inspect({fields: fields, files: files})); | |
}); | |
// handler for receving a chunk of file from web app - listens for 'chunk' on form | |
form.on('chunk', function(chunk) { | |
depotRequest.write(chunk); // send a chunk at a time to depot, see http://nodejs.org/api/http.html#http_request_write_chunk_encoding | |
}); | |
depotRequest.end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment