0
votes

I'm having some issues trying to request an image file from Cloud Clode in Parse.

This is my Parse Cloud Code:

   Parse.Cloud.define("datata", function(request, response) {
    //var message = request.params.message;
    var file = request.params.file;
    //console.log(file);
    var base64 = file.toString("base64");


    var data = new Parse.File("test.jpg", {
        base64: base64
    });

    data.save().then(function() {
        // The file has been saved to Parse.
        console.log("WIN");
    }, function(error) {
        console.log("LOSE");
        // The file either could not be read, or could not be saved to Parse.
    });
});

The problem is when I try to post the file I got this as an answer from the server:

{"code":107,"error":"invalid utf-8 string was provided"}

I'm trying to create custom endpoints for some custom hooks, that why I'm working with Cloud Code.

Anyone have any idea about how can I create and endpoint in Parse Cloud Code for requesting and creating files?

Thanks in advance.

1

1 Answers

0
votes

What JSON response did you get when you POST'd the file?

You need to use the "url" value in order to GET the file.

{"__type":"File","name":"e580f231-90ba-4d24-934c-7f9e7c8652d6-picf1","url":"http://files.parse.com/1315e4d8-f302-4337-adbe-d8650ab5c312/e580f231-90ba-4d24-934c-7f9e7c8652d6-picf1"}

So, in the example above which is very similar to the response when a file type is POST'd, you would use the value of the "url" tag in a http/GET.