Page 1 of 1

decode response from file api after upload

Posted: Mon Sep 07, 2015 5:20 pm
by Jarl Gjessing

I have successfully uploaded a file to the file api.
And console.log(data) say:
success
Object { filename="cc0ef18b-2301-4223-86cb-35b90d51e382.betaling.pdf", fileurl="https://api.appery.io/re...b90d51e382..."}
filename

"cc0ef18b-2301-4223-86cb-35b90d51e382.betaling.pdf"
fileurl

That is all and well, but how can I read the filename?
Sorry for the noop question


decode response from file api after upload

Posted: Mon Sep 07, 2015 8:49 pm
by Serhii Kulibaba

Hello,

I am sorry, not sure I understand you correctly. Please specify your question.

this is filename:"cc0ef18b-2301-4223-86cb-35b90d51e382.betaling.pdf". What do you need to get?


decode response from file api after upload

Posted: Tue Sep 08, 2015 5:12 am
by Jarl Gjessing

Hi, thanks
Well, I see the filename :-) I just want to be able to gain access to the variable in the object.
So, I tried json.stringify(data) to output the object, that returned the object as a string just fine. Then I tried data.settings, and I got undefined.
So my question is in "Run Javascript" in Appery, how to I get access to the objects variables? Image

Here you see the "Run JavaScript" code.
The alert contains:
Your file was successfully uploaded with id: [{"success":{"filename":"b707fbd0-b67f-4340-959d-c41ae2aa8b94.betaling.pdf","fileurl":"https://api.appery.io/rest/1/db/files..."}}]

So I try to do data.success or data.filename both returns undefined :-(


decode response from file api after upload

Posted: Tue Sep 08, 2015 8:47 am
by Illya Stepanov

Hi Jarl - Could you please re-attach the image to your post.


decode response from file api after upload

Posted: Tue Sep 08, 2015 9:11 am
by Jarl Gjessing

decode response from file api after upload

Posted: Tue Sep 08, 2015 9:47 am
by Illya Stepanov

Could you please also show the exact returned object that you're getting?


decode response from file api after upload

Posted: Tue Sep 08, 2015 10:21 am
by Jarl Gjessing

Sorry, figured it out I think.. It's an array,that is why I could not access it directly. To get access I need to write: data[0].success.filename


decode response from file api after upload

Posted: Tue Sep 08, 2015 11:46 am
by Illya Stepanov

Yes, you are right Jarl! Glad everything is OK now.