I'm trying to upload a file to a remote server, get the path for that file on that server, and then save it in a record to my own API. Over half the time, the code crashes because returnedNewFile is undefined (though I've checked console.log(newFile) in the previous .then() function and it's always a promise object. What could be causing this behavior? What could be causing returnedNewFile to sometimes be null/undefined? I'm using Django REST + django-rest-json-api + ember.js 2.6, and this code is in a component's javascript file. Thank you in advance!
store.findRecord('file', folderid).then(function(folder) {
var file = fileList.pop();
var newFile = fm.uploadFile(folder, file.name, file);
return newFile;
}).then(function(returnedNewFile) {
var name = returnedNewFile.get('name');
var path = returnedNewFile.get('path');
var doc = store.createRecord('document', {
name: name,
path: path,
});
console.log("doc: ", doc);
doc.save();
return doc;
}).then(function(doc) {
console.log("hi number three");
var grant = store.createRecord('grant', {
department: department,
number: number,
document: doc,
});
grant.save();
return grant;
}).then(null, function(error) {
console.log("Oops: " + error.message)
});
Aucun commentaire:
Enregistrer un commentaire