I suggest that you use nodejs modules to handle the parsing of the multipart form, and the FTP. I can make some suggestions.
- Formidable is a nice npm module for form processing. https://www.npmjs.com/package/formidable
- node-ftp-client is nice for ftp: https://github.com/noodny/node-ftp-client#examples
Some sample code might be:
http.createServer(function(req, res) {
if (req.url === '/upload' && req.method.toLowerCase() === 'post') {
// parse a file upload
var form = new formidable.IncomingForm();
form.uploadDir = uploadDir;
form.parse(req, function(err, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end(util.inspect({fields: fields, files: files}));
// upload to FTP Server here...
// follow the node-ftp-client example I referred above.
});
return;
}
}).listen(port);
Here’s a start; a working example of an API Proxy that uses a hosted target , and the formidable module.