javascript - Saving an Image from URL in Parse.com using CloudCode -


i have been struggling saving file retrieve http request a few days now. here code:

    parse.cloud.httprequest({     url: "https://ss1.4sqi.net/img/categories_v2/food/vietnamese_88.png",     success: function(httpimgfile)      {         console.log("httpimgfile: " + string(httpimgfile.buffer));         var imgfile = new parse.file("imgfile1.png", httpimgfile.buffer);                                                        object.set("location", "newyork"); //object pfobject retrieved earlier         object.set("icon1", imgfile);         object.save(null, {           success: function(gamescore) {             response.success("saved object");           },           error: function(gamescore, error) {             response.error("failed save object");           }         });          },     error: function(httpresponse)      {         console.log("unsuccessful http request");         response.error(responsestring);     } }); 

the error is:

failed with: typeerror: cannot call method 'then' of undefined     @ object.b.file.save (parse.js:2:14963)     @ null.<anonymous> (parse.js:2:30041)     @ e (parse.js:2:6339)     @ parse.js:2:7092     @ g (parse.js:2:6829)     @ c.extend.then (parse.js:2:7077)     @ parse.js:2:30016     @ array.foreach (native)     @ function.x.each.x.foreach (parse.js:1:661)     @ function.b.object._deepsaveasync (parse.js:2:29993) 

the weirdest part error occurs when include line object.set("icon1", imgfile) able to modify location of object without problem. error occurs solely when try save imgfile icon1

any appreciated. thanks!

as per documentation (https://parse.com/docs/js_guide#files) have save parse file before can set on object.

typically:

imgfile.save().then(function () {      ...     object.set("icon1", imgfile);      return object.save();  }).then(function (gamescore) {     response.success("saved object"); }, function (error) {    response.error("failed save object"); }); 

i rewrote part of function illustrate promise pattern, little easier when dealing series of requests this.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -