Everett Chad Nelson
Posts: 0
Joined: Tue Dec 30, 2014 10:44 pm

How do I access {database_url} in Javascript?

I am creating a list of downloadable files for a course app that I'm developing. However, I do not know how to expose {database_url} to javascript (Or whether I even need to do that).

I added a list to my page; added a hyperlink field to the list; and mapped the data service to the list and associated hyperlink.

On the "Data" tab of my page I linked the "fileName" to the link "URL" and the "originalFileName" to the link "Text".

This worked as hoped from a display standpoint, but when I click the link nothing downloads. I'm expecting to be able to download any file in the hyperlink list.

I also tried adding this javascript to modify the "fileName". (value = fileName)

value = "{database_url}/collections/aquamarine/" + value;
return value;

This works in modifying the 'href' for the link, but still no download.

Also, I can see the list in the browser test window, but when I view the page on my mobile device it is blank.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How do I access {database_url} in Javascript?

Hello,

you can access db url with following JS code:

pre

//Where "ToDoDB_settings" is your db settings service.
var dbUrl = ToDoDB_settings.database_url;

/pre

But for your case(to get url for the file in Files collection) you need:

pre

https://api.appery.io/rest/1/db/files/[databaseID]/[fileName]

/pre

So code will be:

pre

//Where "ToDoDB_settings" is your db settings service.
var fileURL = "https://api.appery.io/rest/1/db/files/" + ToDoDB_settings.database_id + "/" + value;

return fileURL;

/pre

Regards.

Everett Chad Nelson
Posts: 0
Joined: Tue Dec 30, 2014 10:44 pm

How do I access {database_url} in Javascript?

I do not think that I'm understanding how to set 'ToDoDB_settings'. I used the name of my service 'AquamarineFileDownloadLinkrestservice1' and got '{"code":"DBFG014","description":"Database with id='undefined' does not exist."}'.

When I replace 'ToDoDB_settings' with the database name or with the collection name I get a modal message 'Error Loading Page'.

How do I know what to replace 'ToDoDB_settings' with?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How do I access {database_url} in Javascript?

Hello,

When you import one of your DB service you will get "settings" service in services..

This service name - is what you need to use.

See details: http://prntscr.com/5n4iao/direct

FYI: This service provides settings for all imported services. See details: http://prntscr.com/5n4j1g/direct

Regards.

Everett Chad Nelson
Posts: 0
Joined: Tue Dec 30, 2014 10:44 pm

How do I access {database_url} in Javascript?

What worked for me was using: MyDatabaseName_settings.database_id

I got confused by the "ToDoDB" part. Now I realize that it is just the name of my database.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How do I access {database_url} in Javascript?

Yes, that's right.

Regards.

Return to “Issues”