Ho avuto difficoltà a salvare un file recuperato da una richiesta HTTP per alcuni giorni. Qui è il mio codice:Salvataggio di un'immagine dall'URL in Parse.com utilizzando CloudCode
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);
}
});
L'errore che ottengo è:
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)
La parte più strana di tutto questo è che l'errore si verifica solo quando includo la linea object.set("icon1", imgFile)
sono in grado di modificare la posizione di object
senza problemi. L'errore si verifica solo quando provo a salvare imgFile
in icon1
Qualsiasi aiuto sarebbe molto apprezzato. Grazie!
da dove proviene la variabile 'object'? Qual è il tipo di 'oggetto'? L'oggetto – wayne
è un PFObject di tipo "OuterList". Probabilmente non ti sarà di grande aiuto anche se –