0

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.

rici
  • 234,347
  • 28
  • 237
  • 341
Diego Ivan
  • 15
  • 5

1 Answers1

0

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.

Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43
  • I always get this: "invalid utf-8 string was provided" – Diego Ivan Jan 05 '15 at 19:36
  • error has to do with how you convert base64 toString for the post. Look over the parse samples(javascript) for POST a file. Verify whether the convert to string is req'd and if it is provide an encoding. – Robert Rowntree Jan 05 '15 at 20:14