Hi Joe.
Thanks for the details.
So there is a problem with that which image needs to be upload next.
How you trying to upload your images. Can you tell me how you invoke these services?
Logan.
Hi Joe.
Thanks for the details.
So there is a problem with that which image needs to be upload next.
How you trying to upload your images. Can you tell me how you invoke these services?
Logan.
Thanks Steve, will try this out.
Logan, here is the implementation for image 1:
codeuploadBinaryHelper(image01_UploadService, Apperyio.storage.Image1_base64.get()); /code
Image1_base64 here is the LSV, uploadBinaryHelper is the upload API from Appery
Here is sample of how I check if LSV is populated before calling the service, I am only showing 2 services here
code
if (image1 !== null) {
Code: Select all
//Call service here
uploadBinaryHelper(image01_UploadService, Apperyio.storage.Image1_base64.get());
}
if (image2 !== null) {
//Call service here
uploadBinaryHelper(image02_UploadService, Apperyio.storage.Image2_base64.get());/code
Hi Joe.
Thanks for the details.
First you need to check your LSV has any value or not then.
var picture1 = Apperyio.storage.Image1_base64.get();
var picture2 = Apperyio.storage.Image2_base64.get();
// try nested if statement.
//check the condition
if (picture1 != "") {
Code: Select all
// use alert for checking LSV value
alert("value is : " + picture1);
// you can call your service
uploadBinaryHelper(image01_UploadService, Apperyio.storage.Image1_base64.get());
} else if (picture2 != "") {
Code: Select all
alert("value is : " + picture2);
// you can call your service
uploadBinaryHelper(image02_UploadService, Apperyio.storage.Image2_base64.get());
} else {
Code: Select all
alert("value is null");
}
let me know the results.
Logan.
Hi Logan,
Thanks for the reply.
I have tried different variations of the if else statement and they don't work. I have no issues uploading images, sequencing is the issue as Steven alluded to, it looks like this is just how those services are executed. I am currently experimenting with $q functions.
Appery, I can't be the first to encounter this issue. Can someone from your development team pleaseweigh in .
The other option I was thinking was, calling the services manually using JS for Example:
Uploadimage1
On Service complete
Uploadimage2
On Service complete
......image3....4....
On Service complete
UploadImageimage5
On Service complete
uploadRawData
Obviously I would be first check if the LSV has value.Can someone please provide guidance how this can be accomplished.
Joe
That's what the $q achieves but in my opinion much simpler.
At first I struggled to understand it and make it work but now I use it a lot in order to ensure things happen in the sequence I want.
If you get stuck I can post another example?
I have been poking around with the $q and I have not achieved desired results and I need to use timers as described above. The drawback with this is that image size differs and if I set the time to; for example, 2 seconds, that may not be enough time to load a 4 MB image over 3G network.
I have also read that service.execute doesn't return a promise object. You have to use complete service event to run services one after the other.
Can someone from Appery or the community please clarify how I would use the complete event using JS and not the mapping page.
Based on the example I gave you with functions func1(), func2(), etc. I would put your service call to uploadImage and uploadRawData inside func1() and func2() [rename as say qUploadImage() and qUploadRaw() and then in those functions you can put the service call and return the promise. Don't use a timeout because that's the same as just calling the upload and it finishes "whenever". You need the promise to make it sequence the way you want.
It'll look like this:
code
function qUploadImage1()
var $q = Apperyio.get("$q");
var $timeout = Apperyio.get("$timeout");
var deferred = $q.defer();
console.log("uploading image #1");
$timeout(function() {
// call your existing service uploadImage1() here
deferred.resolve();
});
return deferred.promise;
/code
Do the same for uploadRawData1 and then duplicate that for each service call and then in your main block of code do
code
var $q = Apperyio.get("$q");
var promises = [];
promises.push($scope.qUploadImage1());
promises.push($scope.qUploadRawData1());
$q.all(promises).then(function() {
console.log("Image and raw data for image #1 now uploaded");
});
/code
That should ensure that qUploadRawData1() only gets called after qUploadImage1() completes.
Thanks Steve,
Did you ever encounter this error and how did you resolve it? I have tried to debug but haven't gotten it right: Uncaught TypeError: Apperyio.get is not a function
at uploadImage_Data. Note that uploadImage_Data is the main function inside the button Submit (shown below)
On My Submit Button I have
codefunction uploadImage_Data(){
var $q = Apperyio.get("$q");
var promises = [];
promises.push($scope.uploadImage1());
promises.push($scope.uploadImage2());
$q.all(promises).then(function() {
console.log("All promises done");
});
}
/code
For Now I am just testing 2 Function (2 images) exactly similar to this except for the actual service name:
code
function qUploadImage1(){
var $q = Apperyio.get("$q");
var $timeout = Apperyio.get("$timeout");
var deferred = $q.defer();
console.log("uploading image #1");
$timeout(function() {
// call your existing service uploadImage1() here
uploadBinaryHelper(image01_UploadService, Apperyio.storage.Image1_base64.get());
deferred.resolve();
});
return deferred.promise;
}
/code