File transfer to FTP server using node.js callout

Hi ,

I am new to Apigee, Can anyone help me out find a solution for below problem.

I would like to send an xml/excel file to FTP server in Apigee edge using Node.js callout?

Can any one give some idea or some sample examples to implement?

I was searching in google but did not get any solution, I am new to Apigee and Node js . Please help

Solved Solved
0 3 8,453
1 ACCEPTED SOLUTION

I suggest that you use nodejs modules to handle the parsing of the multipart form, and the FTP. I can make some suggestions.

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.

https://github.com/DinoChiesa/apiproxy-nodejs-formidable

View solution in original post

3 REPLIES 3

Wow, you're new to BOTH Apigee Edge and node.js, and you selected that combination to solve this problem. Why? Why did you select a technology? Why did you select that particular combination of technologies?

Can you describe more context around the use-case? What is the client? How does the client send the file to Apigee Edge? Why doesn't the client just connect directly to the FTP server? You said "xml/excel". Is it an XML file or an Excel file, or... ? How big is it? What's the request rate?

I am placed in a project where we need to work on apigee edge with node js as the client does not support java.

I am going to send a simple xml through postman client as a multi-part form data where agigee should receive an xml and send to FTP server using node.js callout.

Our application will receive an xml file and it is of size around 1MB.

Not sure about the frequency of receiving the file. For the time being I have 1 file that needs to be sent to ftp server.

I suggest that you use nodejs modules to handle the parsing of the multipart form, and the FTP. I can make some suggestions.

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.

https://github.com/DinoChiesa/apiproxy-nodejs-formidable