Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Does Appery Support $.Deferred and Promises in jqm when calling Services

I know $.Deferred and Promises are widely supported in JQM but does Appery support them specifically when using $.Deferred and Promises to que Appery service calls?

I have been having this issue where I have been trying to call services in sequence and I have written different variations of $.Deferred and Promises code which all yield the wrong results. In my case where I have 6 services 5 for uploading images and 1 service for uploading data the system uploads images and data based on size i.e. smallest to largest.

Can someone from Appery please confirm this. All the code samples I have seen and example are from Angular. I had another thread shown below where there was a lot of back and forth with no resolution. Kindly provide clarity and directions on this.

I can provide code samples I have written and link to App if needed.

https://getsatisfaction.com/apperyio/...

Galyna Abramovych
Site Admin
Posts: 84
Joined: Tue Mar 22, 2016 6:03 pm

Does Appery Support $.Deferred and Promises in jqm when calling Services

Hello Joe,

In our JQM visual builder, services don't use promises, they work with callbacks.

Here, there are some options:

  1. Don't use uploadBinaryHelper. Instead, use the direct REST invocation so that you you have 6 RESTs. 1st - for the first image upload, the complete of which invokes the 2nd REST for the second image upload, the complete of which invokes the 3rd REST for the third image upload and so on. The complete of the 5th image upload invokes the REST for raw data upload.

  2. Don't use uploadBinaryHelper. Instead, use the REST for uploading all the 5 images at a time: https://docs.appery.io/reference#database-api-files-uploading-multipart-data. (this REST will retrieve all the names of the images that have been uploaded). The complete of this service invokes the REST for raw data upload.

    The option 2 is better as sending any images number can easily be defined. Besides, all the images are uploaded in bulk which is much faster.
    Here is a useful code in mapping into the data parameter for sending several files at a time (option 2):
    precodefunction str2ab(str) {
    var buf = new ArrayBuffer(str.length);
    var bufView = new Uint8Array(buf);
    for (var i=0, strLen=str&#46;length; i < strLen; i++) {
    bufView = str&#46;charCodeAt(i);
    }
    return buf;
    }

    var fd = new FormData();

    var img1 = Apperyio&#46;storage&#46;Image1_base64&#46;get();
    var ab = str2ab(img1);
    var blob = new Blob([ab], {type: "image/jpeg"}); &#47;&#47;here you can set file's mime type
    fd&#46;append('img1&#46;jpg', blob); &#47;&#47;here you can set file's name

    var img2 = Apperyio&#46;storage&#46;Image2_base64&#46;get();
    ab = str2ab(img2);
    blob = new Blob([ab], {type: "image/jpeg"}); &#47;&#47;here you can set file's mime type
    fd&#46;append('img2&#46;jpg', blob); &#47;&#47;here you can set file's name

    var img3 = Apperyio&#46;storage&#46;Image3_base64&#46;get();
    ab = str2ab(img3);
    blob = new Blob([ab], {type: "image/jpeg"}); &#47;&#47;here you can set file's mime type
    fd&#46;append('img3&#46;jpg', blob); &#47;&#47;here you can set file's name

    &#47;&#47;&#47;&#47; add here other images

    return fd;/code/pre

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Does Appery Support $.Deferred and Promises in jqm when calling Services

Hi Galyna,

Thanks for sending me on the right path I have spent countless hours on deferred and promises. But I am worried I may have to go back to the drawing board.

Of the two options, I think I would like to pursue option 1 for now (hopefully the quickest to help finish & publish the APP) and option 2 as a future enhancement. But I still have some questions.

You say, Don't use uploadBinaryHelper but use direct REST invocation.Of the two ways: Cordova and Webupload they both leverage uploadBinaryHelper and in my case I am using Webupload so that I can store my 5 images as Base64.

I have a total of 6 services right now Image1....Image5 and uploadRawData. Yes I am using uploadBinaryHelper as follows: code uploadBinaryHelper(image01_UploadService, Apperyio&#46;storage&#46;Image1_base64&#46;get()); /code

My question is without using the uploadBinaryHelper, how would I call this service using direct REST invocation.

My other question is assuming I use the direct REST invocation what would be the correct way using JS to control the call such as:

code
service&#46;execute({
success: function(e) {
&#47;&#47;Success handler here
},
error: function(e) {
&#47;&#47;Error handler here
},
complete: function(e) {
&#47;&#47;Call image2 here&#46;
},
});

/code

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Does Appery Support $.Deferred and Promises in jqm when calling Services

Hello Joe,

Unfortunately custom JS code and promises are outside the scope of standard Appery.io platform support. You may consider purchasing Advisory Pack to get more in-depth help on this question. Here is more information about it: http://appery.io/services/#Advisory_Pack

Joe7349603
Posts: 0
Joined: Tue Jan 27, 2015 11:08 pm

Does Appery Support $.Deferred and Promises in jqm when calling Services

Thanks Evgene, but I was not asking for custom coding of my app but clarification specifically on how ApperyIO recommends service calls inJS.

I am afraid that the standard answer we are now getting "Unfortunately custom JS code and promises are outside the scope....." is an easy way to deflect what in some cases are very genuine concerns/issues that if resolved would be beneficial to the entire community.

If you look at the discussion here https://getsatisfaction.com/apperyio/... this was an important discussion that was going on that I think Appery should have come forward and cleared the air on Promises but instead you guys chose to ignore inquiries.

I understand there is a need for you guys to draw the line but don't lose the balance otherwise you will start loosing people in the fear of developed solutions are not sustainable in the long run especially in a platform that is not as mainstream but very good platform nevertheless.

Return to “Issues”