几天来,我一直在努力保存从 HTTP 请求中检索到的文件。这是我的代码:
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 is a PFObject retrieved earlier
object.set("icon1", imgFile);
object.save(null, {
success: function(gameScore) {
response.success("saved object");
},
error: function(gameScore, error) {
response.error("failed to save object");
}
});
},
error: function(httpResponse)
{
console.log("unsuccessful http request");
response.error(responseString);
}
});
我得到的错误是:
Failed with: TypeError: Cannot call method 'then' of undefined
at Object.b.File.save (Parse.js:2:14963)
at null.<anonymous> (Parse.js:2:30041)
at e (Parse.js:2:6339)
at Parse.js:2:7092
at g (Parse.js:2:6829)
at c.extend.then (Parse.js:2:7077)
at Parse.js:2:30016
at Array.forEach (native)
at Function.x.each.x.forEach (Parse.js:1:661)
at Function.b.Object._deepSaveAsync (Parse.js:2:29993)
关于这一切的最奇怪的部分是,只有当我包含object.set("icon1", imgFile)
我能够修改位置而object
没有问题的行时才会发生错误。该错误仅在我尝试保存imgFile
到时发生icon1
任何帮助将不胜感激。谢谢!