I am currently working on an app using AngularJS and the MediaFire JavaScript SDK to perform various tasks.
One specific task I am struggling with is creating a folder during an upload process, which returns a 'folderkey'. I would like to use .then in my service functions to maintain clean code in my controller while continuing with the file upload process.
Despite conducting research, I am still unsure about how to achieve this. An example in my context would greatly aid my understanding of the necessary steps.
Currently, I invoke this function in my service to create a folder:
mediafireService.createFolder('TestFolder');
I envision the implementation as:
mediafireService.createFolder('TestFolder')
.then(function(folderkey){
//Upload file into that folder
});
Below are 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);
};
I am unsure if JavaScript supports this functionality natively or if an external service is required. I find myself a bit lost on this aspect at the moment.
Any assistance on this matter would be highly appreciated. Thanks.