使用Rest Client检索时,Parse File为空

时间:2015-07-08 21:55:25

标签: parse-platform

我尝试过两种方式使用云代码创建解析文件。第一种方法是使用添加的Byte API,另一种是创建字节数组。使用字节数组方法,我能够访问我生成的文件,并使用示例代码中的parse文件返回的URL获取所需的文件。但是,当我使用Parse Rest Client时,它返回了一个空白文件。

文件生成返回的文件:http://files.parsetfss.com/02247568-8b6c-4f69-b50c-a3daefb84755/tfss-07089997-8a39-436d-82e0-71b36eeed42c-userID4_car.csv

Rest Client使用主密钥返回的文件:http://files.parsetfss.com/02247568-8b6c-4f69-b50c-a3daefb84755/tfss-9f4f17da-9e8b-4d40-9e26-31ee915fa51e-userID4_car.csv

Rest Client使用Master Key Off返回的文件:http://files.parsetfss.com/02247568-8b6c-4f69-b50c-a3daefb84755/tfss-c448fa26-fbef-4195-ae16-a66217d94a45-userID4_car.csv

使用cURL返回文件:http://files.parsetfss.com/02247568-8b6c-4f69-b50c-a3daefb84755/tfss-6c743684-c081-478c-8fdd-df64bfa6d855-userID4_car.csv

var Buffer = require('buffer').Buffer;

function stringToBytes(str) {

    var bytes = [];

    for (var i = 0; i < str.length; ++i) {

        bytes.push("0X"+byteToHex(str.charCodeAt(i)));
    }

    return bytes;
}

function byteToHex(b) {
    var hexChar = ["0", "1", "2", "3", "4", "5", "6", "7","8", "9", "A", "B", "C", "D", "E", "F"];
    return hexChar[(b >> 4) & 0x0f] + hexChar[b & 0x0f];
}


Parse.Cloud.define("exportData", function (request, response) {
    var jsonString =[{"Vehicle":"BMW","Date":"30, Jul 2013 09:24 AM","Location":"Hauz Khas, Enclave, New Delhi, Delhi, India","Speed":42},{"Vehicle":"Honda CBR","Date":"30, Jul 2013 12:00 AM","Location":"Military Road,  West Bengal 734013,  India","Speed":0},{"Vehicle":"Supra","Date":"30, Jul 2013 07:53 AM","Location":"Sec-45, St. Angel's School, Gurgaon, Haryana, India","Speed":58},{"Vehicle":"Land Cruiser","Date":"30, Jul 2013 09:35 AM","Location":"DLF Phase I, Marble Market, Gurgaon, Haryana, India","Speed":83},{"Vehicle":"Suzuki Swift","Date":"30, Jul 2013 12:02 AM","Location":"Behind Central Bank RO, Ram Krishna Rd by-lane, Siliguri, West Bengal, India","Speed":0},{"Vehicle":"Honda Civic","Date":"30, Jul 2013 12:00 AM","Location":"Behind Central Bank RO, Ram Krishna Rd by-lane, Siliguri, West Bengal, India","Speed":0},{"Vehicle":"Honda Accord","Date":"30, Jul 2013 11:05 AM","Location":"DLF Phase IV, Super Mart 1, Gurgaon, Haryana, India","Speed":71}];
    var CSVString = JSONToCSVConvertor(jsonString, "export", true);
    var dataForFile = new Buffer(CSVString).toString('base64');
    var dataForFile2 = stringToBytes(CSVString);
    var parseFile = new Parse.File("userID4_car.csv", dataForFile2);
    parseFile.save().then(function() {
        response.success(parseFile);
    }, function(error) {
        response.error(error);
    });

});

0 个答案:

没有答案