简体   繁体   中英

How to download a file using Parse.Cloud.httpRequest for content type zip

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM