Im currently building an app using angularjs and using the mediafire javascript SDK to do some tasks.
Now i'm in a situation where when an upload happens i will need to create a folder, this function returns a 'folderkey'. Now to keep my code clean in my controller i would like to use .then on my service functions to continue through the process of uploading a new file.
I have done a fair bit if research but i am still left baffled by how i would do it. Perhaps an example in my situation will help me understand what needs to be done.
Currently run this function to my service which will create a folder.
mediafireService.createFolder('TestFolder');
I would like to have
mediafireService.createFolder('TestFolder');
.then(function(folderkey){
//Upload file into that folder
});
Here is my factory functions.
function createFolder(folderName){
var options = { foldername: folderName };
login(function(){
app.api('folder/create', options, function(data) {
console.log(data.response.folderkey);
return data.response.folderkey;
});
});
}
function login(callback){
app.login({
email: 'email',
password: 'pass'
}, callback);
};
Reading around i'm not completely certain if javacript has this natively or if we have to use an external service for it or not. Kind of lost on it at the moment.
Any help would be greatly appreciated, Thanks.