3

I wanted to create a scheduled Parse job to download a zip file. I tried it with Parse.Cloud.httpRequest(), but it seems like it works only for json and url encoded content type.

How exactly can I get this done from cloud code?

Parse.Cloud.define("getPage", function(request, response) {
Parse.Cloud.httpRequest({
      url: 'http://www.nseindia.com/content/historical/EQUITIES/2015/MAY/cm12MAY2015bhav.csv.zip',
      headers: {
          "Content-type": "application/zip", 
          "Expires": "0", 
          "Content-disposition": 'attachment; filename="cm12MAY2015bhav.csv.zip"', 
          "User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36"
      },
      success: function(httpResponse) {
        console.log("Response-text:"+ httpResponse.text);
        console.log("Response-text:"+ httpResponse.data);
        //response(httpResponse.text);
      },
      error: function(httpResponse) {
        console.log("Error hit, error: "+ httpResponse.text);
        //response('Request failed with response code ' + httpResponse.status);
      }
    });

});

The above code gives out "Undefined" for httpResponse.data.

sudheeshcm
  • 3,310
  • 4
  • 14
  • 21

1 Answers1

0

Data is going to be JSON or something of the sort. If it's a file, use httpResponse.buffer.

AlexKoren
  • 1,605
  • 16
  • 28