Page 1 of 1

retrieve File Name from Files collection

Posted: Tue Feb 10, 2015 4:52 pm
by Kah Wee

I have been looking through the tutorials, but haven't seen a solution to address this.

I have 2 collections which I am trying to link (Files collection contains the file uploaded, Details collection contains specific details about the same file).

Understand that the best approach would be to
I. Get filename from Files collection
http://prntscr.com/63fhrh

II. Populate the filename into Details collection as a string
http://prntscr.com/63fiop

My approach is:

  1. Invoke upload_service first (to Files collection), then get a response from Files collection for filename. (my mapping so far)
    http://prntscr.com/63fk1q

  2. The response will be mapped to an invisible label.
    http://prntscr.com/63fkr5

  3. Invoke files_details_service (to Details collection). Both files details and filename should be sent in.

    For I., I am having trouble getting a response from Files collection. It is returning "undefined", and I am not able to see what is wrong from browser network.
    http://prntscr.com/63flif

    Am I on the right track, or is there another way to do this?

    Thank you.


retrieve File Name from Files collection

Posted: Wed Feb 11, 2015 1:49 am
by Yurii Orishchuk

Hi Kah,

Yes you on the right direction.

But you have wrong response parameters for "upload" service.

See about correct response parameters for "upload" service. And do the same:
http://prntscr.com/63mq4g/direct

So correct mapping after changes should be like this:
http://prntscr.com/63mpqw/direct

Regards.


retrieve File Name from Files collection

Posted: Wed Feb 11, 2015 4:02 am
by Kah Wee

Thank you Yurii!


retrieve File Name from Files collection

Posted: Wed Feb 11, 2015 8:19 am
by Kah Wee

I have a followup problem related to 2 & 3.
======

  1. The response will be mapped to an invisible label.
    http://prntscr.com/63fkr5

  2. Invoke files_details_service (to Details collection). Both files details and filename should be sent in.
    ==========

    I have created 2 services, upload_service (upload to Files collection) and create_details_service (upload to Details collection),
    http://prntscr.com/63ovzu

    with both are linked to "Upload" button. Upload_service (via handler) is to be executed first, then create_details_service will be executed subsequently.
    http://prntscr.com/63ow5q

    Theoretically, I should get this result:

  3. Click on "Upload" button, upload_service will occur.

  4. Once file is uploaded into Files collection, a success response with filename will be returned and populated into the invisible label.

  5. create_details_service will be executed.

  6. filename and other details (type, name) will be populated to Details collection.

    However, I found that the execution is in the following order: 1 - 3 - 4 - 2
    Reason I concluded this was because I got the "Success" alert from create_details_service first, before I got "Upload Successful" from the upload handler.
    http://prntscr.com/63oywm

    Therefore, I will always get an empty value returned to Details collection as the invisible label is not populated yet.
    http://prntscr.com/63oy5a - (row 2, value was from previous upload, and I did not clear the value)

    Appreciate your advice on this. Sorry for the long explanation, I hope this gives you enough details for analysis. Thank you.


retrieve File Name from Files collection

Posted: Wed Feb 11, 2015 8:54 am
by Kah Wee

It's ok, just found out JS is async. Found the solution here.

http://devcenter.appery.io/documentat...

Thanks!


retrieve File Name from Files collection

Posted: Thu Feb 12, 2015 2:00 am
by Yurii Orishchuk

Hi Kah,

Glad you solved this question.

Thanks for this update.

Regards.